简体   繁体   中英

iOS Storyboard Switch to a View that has no segue on AppDelegate

I have a one time agreement view that will only show up when user launches app first time.

I use storyboard IOS 5.1 and My rootview is a navigationviewcontroller. My agreement view has no connection with navigation controoler I just want to present a modalview pop up then dismiss the view: 在此输入图像描述

I use following code but it doesn't do anything app just continues and launches navigationviewcontroller I put flags, yes app enters the if statement. :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
       if(login==ok){
       UIStoryboard *storyboard = [UIApplication sharedApplication].delegate.window.rootViewController.storyboard;
        UIViewController *loginController = [storyboard instantiateViewControllerWithIdentifier:@"AgreementViewController"];
        [self.window.rootViewController presentModalViewController:loginController animated:YES];
        }
return YES;

}

How can I switch a viewcontroller that has no connection to storyboard and dismiss it?

In the app I've been working on last weekend I had a similar situation. I wanted to show a seperate storyboard the first time for a guided setup. My code looked pretty much the same as yours and it gave me a warning when I was debugging it. This was because of the fact that the rootViewController I was trying to present my one-time ViewController on, isn't visible at this point in the app.

So, instead of presenting my one-time view controller "on" the rootViewController, I decided to set my one-time view controller as the rootViewController. In your case it would be something like:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if(login == ok) {
        UIStoryboard *storyboard = [UIApplication sharedApplication].delegate.window.rootViewController.storyboard;
        UIViewController *loginController = [storyboard instantiateViewControllerWithIdentifier:@"AgreementViewController"];
        [self.window setRootViewController:loginController];
    }

    return YES;
}

To dismiss it, you could probably add a segue from your one-time view controller to your first view controller or you could use code similar to the one in your question.

Another approach would be to do the check and view switching in your first "normal" view's viewDidAppear, instead of in the AppDelegate.

Hopefully this will point you in the right direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM