[英]Why doesn't performSegueWithIdentifier work inside viewDidLoad?
I'm trying to trigger a storyboard segue as soon as viewDidLoad is called on a view controller. 一旦在视图控制器上调用viewDidLoad,我就试图触发故事板segue。 The segue has an identifier attached, and works fine when called from inside a method thats linked to a button or other control.
segue附加了一个标识符,当从链接到按钮或其他控件的方法内部调用时,它可以正常工作。 But it doesn't work inside of viewDidLoad.
但它在viewDidLoad中不起作用。 It just silently fails.
它只是默默地失败了。 Is there some rule about segue's being ignored in viewDidLoad?
在viewDidLoad中是否有一些关于segue被忽略的规则?
I've tried both this: 我试过这两个:
[self performSegueWithIdentifier: @"mySegue"
sender: self];
and this: 还有这个:
[self dismissViewControllerAnimated:YES completion:^() {
[self performSegueWithIdentifier:@"mySegue" sender:self];
}];
Neither work. 都没有工作。
You can not dismiss a view controller that isn't presented yet. 您无法关闭尚未显示的视图控制器。
didLoad
has purely memory management functions, you can use it as (part of a) constructor. didLoad
具有纯粹的内存管理功能,您可以将其用作(部分)构造函数。 What may work, is to start a segue in viewDidAppear
, however I would suggest to start with the view you want at the first time. 可能有用的是在
viewDidAppear
启动一个segue,但是我建议在第一次开始时使用你想要的视图。
Most likely reason could be that the OS ignores second screen transition call while one is in progress. 最可能的原因可能是操作系统在进行中时忽略了第二个屏幕转换调用。 In your ViewDidLoad, the view transition (of the current view) is still not complete.
在ViewDidLoad中,视图转换(当前视图)仍未完成。 You are asking another transition before it completes and the OS ignores it.
您在完成之前要求另一个转换,操作系统会忽略它。 It must be the reason that the segue works when called from a different function.
它必须是从不同函数调用时segue工作的原因。 Try calling inside ViewDidAppear (or after a time delay)
尝试在ViewDidAppear内部调用(或延迟一段时间后)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.