繁体   English   中英

在didSelectRowAtIndexPath之前调用viewDidLoad

[英]viewDidLoad being called before didSelectRowAtIndexPath

我有一个viewDidLoad (下一个tableView)在didSelectRowAtIndexPath (当前tableView )之前被调用。

我使用'singleton'来保持我的模型,到目前为止,它一直运作良好。 我试图通过对当前表中选择的行didSelectRowAtIndexPath到目的地tableview通过在变量设置(它们是由一个故事板赛格瑞链接) didSelectRowAtIndexPath

但是,在设置行号之前,会调用目标tableviewviewDidLoad didSelectRowAtIndexPath稍后调用,但到那时我已经为目标表设置了我的数据(错误地)。

使用segues时,您不需要didSelectRowAtIndexPath: . 您只需将segue链接到IB中的单元格即可。 在代码中使用这个:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
   CustomViewController *newVC = [segue destinationViewController];
   newVC.property = theDataYouWantToPass;
}

您可以通过传递的sender变量检索行。

UITableViewCell *cell = (UITableViewCell *) sender;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
NSInteger myRow = indexPath.row;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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