There are various issues with your code. First and foremost, you should set the window rootController inside the method of the app delegate
application:didFinishLaunchingWithOptions:
You should avoid playing with it outside this peculiar moment of app launch. Second, considering your first piece of code, what are you actually changing the rootController? Isn't your line:
if (![appDelegate.window.rootViewController isKindOfClass:[UISplitViewController class]]) {
saying that you have already one? Why this test?
Then, this line is useless:
[masterNav popToRootViewControllerAnimated:NO];
assuming you don't do something special in the initWithCoder:
method of the instance of the masterNav class (if we trust the cast put in front of the instance, it is a standard UINavigationController
, but this might just hide the truth set inside the storyboard).
Now, to really answer your question, you need to indicate where exactly is located your "login screen loading code". In what class, and called where? And why are you calling this inside a dispatch_async(dispatch_get_main_queue(), ^{...
block?
Normally, you should be inside the application:didFinishLaunchingWithOptions:
method, which is called on the main thread (== main queue) anyway.
Last question: why are you setting the window root controller in two different places??? Your code is artificially complicated for the problem you try to solve (which is perfectly relevant otherwise).