I got strange behaviour when setting the rootViewController programatically. I am using xib's only and here are scenarios of what I already tried. When I use this code, there is a small blink of black screen before it loads VC correctly.
- (void)setRootVC:(UIViewController *)viewController {
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
[UIView transitionWithView:window
duration:0.0
options:UIViewAnimationOptionTransitionNone
animations:^{ window.rootViewController = viewController; }];
}
When I use different function, it eliminates the blink, but there's another strange behaviour. I got bunch of textfields in the new VC and I am setting one of them to becomeFirstResponder
in viewDidLoad
method, but when the VC loads, the textFieldDidEndEditing
is called, which is totally strange. Here's the code.
- (void)setRootVC:(UIViewController *)viewController {
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
[UIView transitionFromView:window.rootViewController.view
toView:viewController.view
duration:0.0
options:UIViewAnimationOptionTransitionNone
completion:^(BOOL finished){
window.rootViewController = viewController;
}];
}
I am restricted with objective-C, so swift solutions will not be helpful. Thanks for the replies.