[英]iphone UIViewController does not show data passed from the first view controller
[英]Data is not passed to view
我想將在tableView
中選擇的“人類”傳遞給detailViewController
。 我通過情節提要板將它們連接到Interface Builder中,並設置了自己的segue標識符。 調用了NSLog
,但是它返回(null)
。 另外,在detailView中,除了默認內容外,什么都沒有顯示。
我的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];
}
}
還有detailViewController
-(void)setHuman:(Human *)human
{
NSLog(@"%@",employee.name);
employee = human;
nameLab.text = employee.name;
descriptionLab.text = employee.description;
imageViewBig.image = [employee imageForName];
}
提前致謝!
您在setHuman
中的變量human
包含employee
。 因此,您應該在函數中將變量human
分配給DetailViewController
的@property
human
。 或者更好的是,只需從外部分配屬性: detailViewController.human = employee
。
您的NSLog
返回null,因為您在將human
分配給employee
之前調用了它。
也許選擇較少重復的ivar名稱會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.