iOS App Goes to Black Screen
I finally solved this. After weeks of battling it and trying everything from ripping ALL of my code out, it turns out that the view outlet for my view in the storyboard had become double-linked to both "View" and one of my text fields in that view. Like this:
I have since deleted the linkage to the text field, but show the correct linkage here:
Interestingly, I am unable to reproduce this accidental connection in the UI, so I am not sure how that even happened. Anyway, I hope this helps others that might come across this.
I was faced with the same issue in my device. I managed to fix it by setting the application's main interface via xcode: MyApplication → Main Interface → LaunchScreen.storyboard
(or Main.storyboard
).
Cheers! :)
I'd say the problem is this line:
dispatch_async(dispatch_get_main_queue(), {
self.performSegueWithIdentifier("toWelcomeView", sender: self);
});
You're trying to do a segue to another view while this view has not yet appeared (view will appear). That's very iffy, and that's why sometimes it is in fact failing. I'm a bit surprised that you don't report seeing an error message in the Console warning that you're trying to segue from a view controller whose view is not yet in the interface.
As an interim measure, you might move your call to self.RetrieveRegistration()
into viewDidAppear:
and see if that helps.
But in the long term, you're just going about this the wrong way. Your goal seems to be to launch into one view controller under some circumstances and into another under other circumstances. The place to put all that logic is up front in applicationDidFinishLaunching
, so that your rootViewController
itself is different depending on the situation.
For example, imagine the following very simple situation: our storyboard contains just two view controller, RegistrationViewController and RootViewController (with a storyboard identifier "root"
), with a presentation segue from the first to the second. In RegistrationViewController we ask for registration info, such as a "username"
, which we place in the NSUserDefaults. Then we segue to the RootViewController. All well and good, but our goal hereafter is that the user should never see RegistrationViewController again. This is easily taken care of in the app delegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if let rvc = self.window?.rootViewController {
if NSUserDefaults.standardUserDefaults().objectForKey("username") as? String != nil {
self.window!.rootViewController = rvc.storyboard!.instantiateViewControllerWithIdentifier("root")
}
}
return true
}