简体   繁体   English

performSegueWithIdentifier和viewDidLoad

[英]performSegueWithIdentifier and viewDidLoad

MainViewController: MainViewController:

[self performSegueWithIdentifier:@"showNextVC sender:self];

Segue destination controller: Segue目的地控制器:

- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"Show text!");
[self performSegueWithIdentifier:@"showSignUp" sender:self]; }

Why doesn't the code from the destination controller's viewDidLoad method execute? 为什么目标控制器的viewDidLoad方法中的代码不执行?

viewDidLoad is called when the ViewController object is created loading nib file. 加载nib文件时创建ViewController对象时调用viewDidLoad。 It is not yet attached to the window. 它还没有附在窗户上。 You should call performSegue... call in viewDidAppear. 你应该在viewDidAppear中调用performSegue ... call。

Finally, If you are calling performSegue directly without any action being performed. 最后,如果您直接调用performSegue而不执行任何操作。 I'd suggest you take a look at the flow again. 我建议你再看一下这个流程。

if you copied and pasted I'd assume it's because you're missing a " which the compiler should've warned you about 如果你复制和粘贴我会认为这是因为你错过了“编译器应该警告你的”

if the " is there try an NSLog in your prepare for segue and see if it's getting called 如果“在你准备segue时尝试一个NSLog,看看它是否被调用

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

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