Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

like image 662
zakdances Avatar asked Apr 25 '12 02:04

zakdances


2 Answers

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.

like image 76
Matthias Avatar answered Nov 06 '22 18:11

Matthias


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)

like image 42
zolio Avatar answered Nov 06 '22 17:11

zolio