简体   繁体   English

为什么不在viewDidLoad中执行SegueWithIdentifier工作?

[英]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.

相关问题 performSegueWithIdentifier和viewDidLoad - performSegueWithIdentifier and viewDidLoad 为什么在viewDidLoad中添加子视图不起作用 - Why does adding subview in viewDidLoad doesn't work becomeFirstResponder在viewDidAppear中工作,但在viewDidLoad中不起作用 - becomeFirstResponder works in viewDidAppear but doesn't work in viewDidLoad 调用viewdidload中存在的UIImagePickerControler无效 - Calling UIImagePickerControler present in viewdidload Doesn't Work Mapbox selectAnnotation在ViewDidLoad中不起作用,或在ViewDidAppear中首次使用 - Mapbox selectAnnotation doesn't work in ViewDidLoad or first time in ViewDidAppear performSegueWithIdentifier不显示新视图 - performSegueWithIdentifier doesn't show new view 在viewDidLoad和viewDidAppear之前执行performSegueWithIdentifier有时会起作用,有时则不起作用 - performSegueWithIdentifier before viewDidLoad and viewDidAppear sometimes it works and sometimes not 从子级调用父级视图上的performSegueWithIdentifier不会更改视图 - Calling performSegueWithIdentifier on parent view from child doesn't change view iOS presentViewController不会调用viewDidLoad - iOS presentViewController doesn't invoke viewDidLoad UINavigationController:调用viewDidLoad但不影响UI - UINavigationController: viewDidLoad is called but doesn't affect the UI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM