It it possible to override the default view controller from a storyboard to show a different controller instead? This would all happen in the AppDelegate of course.
@Martol1ni I wanted to use your answer, but I also wanted to stay away from unnecessary storyboard clutter so I tweaked your code a bit. However I did give you a +1 for your inspiring answer.
I put all of the following on the default controller.
- (void)gotoScreen:(NSString *)theScreen
{
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UIViewController *screen = [self.storyboard instantiateViewControllerWithIdentifier:theScreen];
[app.window setRootViewController:screen];
}
And then where the logic happens I'll call the following as needed.
if(myBool == YES) {
[self gotoScreen:@"theIdentifier"];
}
I would definately embed a rootView in a UINavigationController, so you have not two, but three views. The one is never launched, just in control of all the otherones. Then implement the methods in it like this:
- (void) decideViewController {
NSString * result;
if (myBool) {
result = @"yourIdentifier";
}
else {
result = @"yourOtherIdentifier";
}
self.navigationController.navigationBarHidden = YES; // Assuming you don't want a navigationbar
UIViewController *screen = [self.storyboard instantiateViewControllerWithIdentifier:@"view1ident"];
[self.navigationController pushViewController:screen animated:NO]; // so it looks like it's the first view to get loaded
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self decideViewController];
}
It never looks like the first view is loaded. If you are using NIBS, you can do everything from AppDelegate though...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With