简体   繁体   中英

Data is not passed to view

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 human in setHuman contains employee . Thus you should assign the variable human to the @property human of the DetailViewController in your function. Or better still, just assign the property from outside: detailViewController.human = employee .

Your NSLog returns null because you call it before assigning human to employee .

Maybe choosing less repetitive ivar names would help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM