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)
Not performing segue
You need to call this self.performSegue
method in dispatch_async
block:
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.async {
self.performSegue(withIdentifier: "seg", sender: self)
}
}
That's because viewDidLoad()
runs in background thread and all UI updates and transitions must be done on Main Thread.
Related Topics
iOS Nsdate() Returns Incorrect Time
Issue with Code Autocompletion/Syntax Highlighting in Xcode 4.X
How to Add Http Headers in Request Globally for iOS in Swift
How to Get the Udid in iOS 6 and iOS 7
Rotation Methods Deprecated, Equivalent of 'Didrotatefrominterfaceorientation'
Xcode Myprojectname-Bridging-Header.H Does Not Exist
Posting JSON Data Using Afnetworking 2.0
Facebook Sdk Login Never Calls Back My Application on iOS 9
Swift3 iOS - How to Make Uitapgesturerecognizer Trigger Function
Implement Pushkit and Test in Development Behavior
How to Password Protect Writing to Nfc Ntag216 Tag on iOS 13 Using Nfc Core
How to Detect When Avplayer Video Ends Playing
Using Uiimagepickercontroller in Landscape Orientation
Force Landscape Viewcontroller in iOS 7
How to Get a View's Current Width and Height When Using Autolayout Constraints