I have two view controller, where before I call the 2nd VC I assign it a few parameters like this:
Results *resultsViewController = [[Results alloc] initWithNibName:nil bundle:nil];
resultsViewController.tempBarcode = barcode;
resultsViewController.address = useraddress;
resultsViewController.key = keyAccess;
resultsViewController.product.text = tempProduct;
The problem is that the last one (product) doesn’t work. The only difference is that “product” is a UILabel while all the rest are NSStrings.
I am trying to avoid creating another NSString for each UILabel in my 2nd VC (since I’ll have many more in the future).
What am I doing wrong here, and how that can be solved?
thank you.
Your issue is that IBOutlets are not initialized until the view is loaded. So the label hasn’t been created yet when you are assigning the text. You need to push it first and let it load.
So you either need to create temporary variables to store the text and then set the label in viewDidLoad, or you need to call back to the parent view controller on viewDidLoad (using a delegate method) to have the parent set the labels.