[英]viewDidLoad being called before didSelectRowAtIndexPath
I have viewDidLoad
(of next tableView) being called before didSelectRowAtIndexPath
(of current tableView
). 我有一个
viewDidLoad
(下一个tableView)在didSelectRowAtIndexPath
(当前tableView
)之前被调用。
I am using a 'singleton' to hold my model and up to now this has been working quite well. 我使用'singleton'来保持我的模型,到目前为止,它一直运作良好。 I am trying to pass on the row selected in the current table in
didSelectRowAtIndexPath
to the destination tableview
(they are linked by a segue in storyboard) by setting by the variable in didSelectRowAtIndexPath
. 我试图通过对当前表中选择的行
didSelectRowAtIndexPath
到目的地tableview
通过在变量设置(它们是由一个故事板赛格瑞链接) didSelectRowAtIndexPath
。
However the viewDidLoad
of the destination tableview
is called before I can set the row number. 但是,在设置行号之前,会调用目标
tableview
的viewDidLoad
。 didSelectRowAtIndexPath
is called later but by then I have set up my data (wrongly) for the destination table. didSelectRowAtIndexPath
稍后调用,但到那时我已经为目标表设置了我的数据(错误地)。
When using segues you do not need didSelectRowAtIndexPath:
. 使用segues时,您不需要
didSelectRowAtIndexPath:
. You just link the segue to the cell in IB. 您只需将segue链接到IB中的单元格即可。 In the code just use this:
在代码中使用这个:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
CustomViewController *newVC = [segue destinationViewController];
newVC.property = theDataYouWantToPass;
}
You can retrieve your row through the sender
variable that is passed. 您可以通过传递的
sender
变量检索行。
UITableViewCell *cell = (UITableViewCell *) sender;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
NSInteger myRow = indexPath.row;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.