I am learning iOS and developing my first iPone app. I want to add a feature to my app: if a user has login before, I want to redirect the user to the main view. otherwise, I want to redirect the user to the login view.
I have read ios change storyboard default view controller at run time, but I am wondering whether I can write the code that decides the root view in AppDelegate. Therefore, I won't have a view that is never launched.
this is my code in AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
MainViewController *rootVC = [[MainViewController alloc] init];
if (userNeverLogin) {
LoginViewController *rootVC = [[LoginViewController alloc] init];
}
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:rootVC];
return YES;
}
this code doesn't work (it will not trigger any error, but it will show nothing in the simulator). how should I revise it? Or it's impossible to do this feature in AppDelegate?
I am sorry that I am a newbie to iOS. I hope this question is not stupid.