[英]when does prepareForSegue get called?
So here is my situation, I have two view controllers: viewControllerA and tableViewControllerB.所以这是我的情况,我有两个视图控制器:viewControllerA 和 tableViewControllerB。 On my viewControllerA, I have a button.
在我的 viewControllerA 上,我有一个按钮。 And when it gets pressed, it will call
当它被按下时,它会调用
self.performSegueWithIdentifier("toControllerB", sender: self)
moreover, I wrote a prepareforSegue function that looks like the following:此外,我编写了一个 prepareforSegue 函数,如下所示:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "toControllerB"){
var controllerB = segue.destinationViewController as tableViewControllerB
controllerB.event = self.event
}
And in my tableViewControllerB I have a function looks like the following在我的 tableViewControllerB 中,我有一个如下所示的函数
var event = nil
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
self.viewDidLoad()
var cell = tableView.dequeueReusableCellWithIdentifier("controllerBCell") as? ControllerBCell ?? ControllerBCell()
//some code
print(event)
return cell
}
And when I run my app, it seems like this tableview function gets called before the prepareforSegue function in ControllerA.当我运行我的应用程序时,这个 tableview 函数似乎在 ControllerA 中的 prepareforSegue 函数之前被调用。 And thus the "event" variable is nil.
因此“事件”变量为零。 Therefore, I am wondering is it possible to call prepareforSegue function before this tableview function in controllerB?
因此,我想知道是否可以在 controllerB 中的 tableview 函数之前调用 prepareforSegue 函数?
Thanks谢谢
The chain is something like this.链条是这样的。
I guess the problem is your line我想问题是你的线路
self.viewDidLoad()
This function is called automatically.这个函数是自动调用的。 I just tried rest of the code at my end and it works fine.
我只是在最后尝试了其余的代码,它工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.