[英]Data is not passed to view
I want to pass an "human" that was selected in a tableView
to a detailViewController
. 我想将在
tableView
中选择的“人类”传递给detailViewController
。 I connected them in Interface Builder via Storyboards and set up an own segue identifier. 我通过情节提要板将它们连接到Interface Builder中,并设置了自己的segue标识符。 The
NSLog
is called but it returns (null)
. 调用了
NSLog
,但是它返回(null)
。 Also, the in the detailView, nothing is shown but the default content… 另外,在detailView中,除了默认内容外,什么都没有显示。
My tableViewController
: 我的
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
还有
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
. 您在
setHuman
中的变量human
包含employee
。 Thus you should assign the variable human
to the @property
human
of the DetailViewController
in your function. 因此,您应该在函数中将变量
human
分配给DetailViewController
的@property
human
。 Or better still, just assign the property from outside: detailViewController.human = employee
. 或者更好的是,只需从外部分配属性:
detailViewController.human = employee
。
Your NSLog
returns null because you call it before assigning human
to employee
. 您的
NSLog
返回null,因为您在将human
分配给employee
之前调用了它。
Maybe choosing less repetitive ivar names would help. 也许选择较少重复的ivar名称会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.