I'm trying to trigger a storyboard segue as soon as viewDidLoad is called on a view controller. The segue has an identifier attached, and works fine when called from inside a method thats linked to a button or other control. But it doesn't work inside of viewDidLoad. It just silently fails. Is there some rule about segue's being ignored in viewDidLoad?
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.
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.
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. 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. Try calling inside ViewDidAppear (or after a time delay)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With