I am using a navigation based iPhone application, and I defined an IBOutlet propert in the inner view and synthesized it,
The issue is when I want to set the IBOutlet value before pushing the new view controller, the value won’t be set. Here is a snippet from the code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MealDetailViewController *mealViewController = [[MealDetailViewController alloc] initWithNibName:@"MealDetailViewController" bundle:nil];
MealsModel *model = (MealsModel *)[_items objectAtIndex:indexPath.row];
NSLog(model.Name);// here it writes the name right as a string
//mealViewController.lblName.text=model.Name;
[[mealViewController lblName]setText:model.Name];
[[mealViewController txtDesc]setText:model.Description];
[self.navigationController pushViewController:mealViewController animated:YES];
[mealViewController release];
}
I didn’t face like these issues in the previous versions of Xcode.
It’s to do with when your view controller’s views are being created.
When you do
you haven’t loaded it’s view yet so lblName will be
nil.Try either
(a) Explicitly asking for the view, triggering the subviews to be created :
or
(b) Letting the navigation controller create the views for you
or
(c) Store the values in the mealViewController as properties
MealViewController.h
MealViewcontroller.m
and instead of setting the label directly, set the properties instead.
Then, in your newWillAppear, setting them
(c) is the more correct way to do it – (a) and (b) both fail if your view controller’s view is unloaded by a low memory warning.