I am attempting to use a UIViewController (View Controller) with a table view to send data to another UIViewController (Detail View Controller). My code looks like this:
//ViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"grapedetail"];
detail.grape = [self.grapes objectAtIndex:indexPath.row];
currentGrape = [self.grapes objectAtIndex:indexPath.row];
NSLog(@"%@",currentGrape.searchName);
[self.navigationController pushViewController:detail animated:YES];
[self performSegueWithIdentifier:@"toGrapeDetail" sender:self];
}
//DetailViewController.m
- (void)viewDidLoad
{
//obtain grape from table view
//grape = ((ViewController *)self.presentingViewController).currentGrape; //I have also tried this method for obtaining the variable with the same result
NSLog(@"Detail view says: %@",grape.searchName);
//etc...
}
After I build the app I go to the View Controller and select a table cell to go to the Detail View Controller. Here is my output log:
2012-07-23 08:13:27.430 GrapeKeeper[593:f803] Detail view says: (null)
2012-07-23 08:13:27.432 GrapeKeeper[593:f803] Alarije
From this it seems that the detail view viewDidLoad
is being called before the original VC's didSelectRowAtIndexPath
, even though I clearly want the latter to happen first so that the variable passes correctly. What can I do to fix this?