Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to decide rootView in AppDelegate
    text
    copied!<p>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.</p> <p>I have read <a href="https://stackoverflow.com/questions/10610012/ios-change-storyboard-default-view-controller-at-run-time">ios change storyboard default view controller at run time</a>, 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. </p> <p>this is my code in AppDelegate:</p> <pre><code>- (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; } </code></pre> <p>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?</p> <p>I am sorry that I am a newbie to iOS. I hope this question is not stupid.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload