When creating a new view controller to be pushed onto the stack, what is the correct method to use to populate that view controller with data?
I have a data object that I need to send to the view controller, which will then set it’s text fields, etc. with the data.
ItemDetailViewController_iPad *detailViewController = [[ItemDetailViewController_iPad alloc] initWithNibName:@"ItemDetailViewController_iPad" bundle:nil];
[detailViewController populateWithData:_data];
[self.navigationController pushViewController:detailViewController animated:YES];
in ItemDetailViewController_iPad:
-(void) populateWithData:(Item*)_data
{
self.data = _data;
self.navigationItem.title = self.data.title;
self.descriptionText.text = self.data.desc; //the text does not get updated - it's the default text from the nib file
NSLog(@"Desc: %@", self.data.desc); //this logs valid data
}
You can also declare a property in that VC and then set that property before pushing it. Then in the viewDidLoad method for the pushed VC, set the view’s title and text field.