Perform Segue on Viewdidload

Perform Segue in ViewDidLoad

You can't use performSegue() from within viewDidLoad(). Move it to viewDidAppear().

At viewDidLoad() time, the current view isn't even attached to the window yet, so it's not possible to segue yet.

Perform Segue From viewDidLoad()

Need to perform segue at right place.you are tried to loading another view before first one in hierarchy.So viewDidAppear is called you have a fully loaded view to modify.

   - (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSegueWithIdentifier:@"myNextControllerSegue" sender:nil];
}

To remove that flickering, just hide the view in your viewWillApear method.

otherwise as quick search you can do that into main thread also like below

dispatch_async(dispatch_get_main_queue(), { () -> Void in   
//perform segue
})

Perform Segue on ViewDidLoad

I answered a similar question where the developer wanted to show a login screen at the start. I put together some sample code for him that can be downloaded here. The key to solving this problem is calling things at the right time if you want to display this new view controller, you will see in the example you have to use something like this

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];

[self presentModalViewController:vc animated:YES];
}

I also have an explanation of how segues and storyboards work that you can see here

perform segue in viewDidLoad() without navigation controller in Swift

You can use this code for navigation.

    let vc : UIViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ConnectionCheckToMain") as! UIViewController;
self.presentViewController(vc, animated: true, completion: nil)

performSegueWithIdentifier not working if called from viewDidLoad

EXPLANATION:

Your View hasn't appeared yet when you call your checkStoredUser().

EASY FIX:

Put it in viewDidAppear() like this:

override func viewDidAppear(animated:Bool) {
super.viewDidAppear(false)
checkStoredUser()
}

prepareForSegue gets called before ViewDidload in a VC with container view

Try to initialize these variables not in the viewDidLoad, but in the prepareForSegue method.



Related Topics



Leave a reply



Submit