簡體   English   中英

數據未傳遞給查看

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM