Reputation: 87
I have an app with several views but I want to make sure it always loads into the same view.
Basically the app is password protected and I need to always make sure it loads into the password view.
How can I go about doing this.
Thanks
Upvotes: 0
Views: 83
Reputation: 14251
If you always want to the application to launch into the same UIViewController you need to set the RootViewController of your application. You can do this in the Interface Builder by ticking the box that says "Is Initial View Controller"
or in your (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method you can set the rootViewController as
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//...
self.window.rootViewController = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"MyLoginViewControllerStoryboardID"];
return YES;
}
Note that you then have to set the storyboard ID properly in the Interface Builder. That is
Also, on a side note, if you want to show the LoginViewController only if the user is currently not logged in you can do something a like this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
BOOL isLoggedIn = [[NSUserDefaults standardDefaults] boolForKey:@"IsLoggedIn"];
NSString *rootStoryboardID;
if(isLoggedIn) {
rootStoryboardID = @"LoginViewControllerStoryboardID";
} else {
rootStoryboardID = @"MainViewControllerStoryboardID";
}
self.window.rootViewController = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:rootStoryboardID];
return YES;
}
Hope it helps!
Upvotes: 2
Reputation: 2169
Assuming you're using storyboards:
Upvotes: 0