xcode Segue 不会使用 performSegueWithIdentifier 加载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11473371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Segue will not load using performSegueWithIdentifier
提问by jimbob
I have given my segue the identity modaltomenu
我已经给了我的 segue 身份 modaltomenu
in my code I am calling the segue with the following:
在我的代码中,我使用以下命令调用 segue:
if([login_status isEqualToString:@"success"]){
//start the menuviewcontroller
[self performSegueWithIdentifier:@"modaltomenu" sender:self];
NSLog(@"segue %@", @"performed");
}
the if statement is always true.
if 语句始终为真。
However the second view is never loaded. This code is ran when the first view loads.
但是,永远不会加载第二个视图。此代码在第一个视图加载时运行。
Why isnt my segue loading?
为什么我的 segue 没有加载?
Thanks!
谢谢!
回答by
You said the code is ran when the first view loads so am I right in assuming its in the viewDidLoad method? If so, try moving that if statement to the viewDidAppear method in the view controller life cycle. ViewDidLoad usually only happens once, whereas viewDidAppear is called every time the view appears on screen. So it would look like...
你说代码在第一个视图加载时运行,所以我在 viewDidLoad 方法中假设它是正确的吗?如果是这样,请尝试将该 if 语句移动到视图控制器生命周期中的 viewDidAppear 方法。ViewDidLoad 通常只发生一次,而每次视图出现在屏幕上时都会调用 viewDidAppear。所以它看起来像......
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:YES];
if([login_status isEqualToString:@"success"]){
//start the menuviewcontroller
[self performSegueWithIdentifier:@"modaltomenu" sender:self];
NSLog(@"segue %@", @"performed");
}
}
回答by LJ Wilson
To troubleshoot further, put this in that VC:
要进一步排除故障,请将其放在该 VC 中:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSLog(@"segue identififer = %@",segue.identifier);
}
And make sure that your code in viewDidLoad
is executing as expected. If it doesn't, you might want to re-think where you call that performSegue
method.
并确保您的代码viewDidLoad
按预期执行。如果没有,您可能需要重新考虑在哪里调用该performSegue
方法。