I want to pass an “human” that was selected in a tableView to a detailViewController. I connected them in Interface Builder via Storyboards and set up an own segue identifier. The NSLog is called but it returns (null). Also, the in the detailView, nothing is shown but the default content…
My tableViewController:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"didSelectRow"]) {
DetailViewController *detailViewController = (DetailViewController *)[segue destinationViewController];
Human *employee = [[Human alloc] init];
employee = [people objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
[detailViewController setHuman:employee];
}
}
And the detailViewController
-(void)setHuman:(Human *)human
{
NSLog(@"%@",employee.name);
employee = human;
nameLab.text = employee.name;
descriptionLab.text = employee.description;
imageViewBig.image = [employee imageForName];
}
Thanks in advance!
Your variable
humaninsetHumancontainsemployee. Thus you should assign the variablehumanto the@propertyhumanof theDetailViewControllerin your function. Or better still, just assign the property from outside:detailViewController.human = employee.Your
NSLogreturns null because you call it before assigninghumantoemployee.Maybe choosing less repetitive ivar names would help.