How to perform Segue in AppDelegate?

前端 未结 3 2076
广开言路
广开言路 2021-02-20 06:28

I am trying to complete an application on IOS 5.1 with Storyboard. Basically I am doing a dropbox app. Since I am using Dropbox SDK link to Dropbox is handled in AppDelegate.m.

相关标签:
3条回答
  • 2021-02-20 06:41

    You can do it like this:

    UINavigationController *navigationController = (UINavigationController*) self.window.rootViewController;
    
    [[[navigationController viewControllers] objectAtIndex:0] performSegueWithIdentifier:@"goToMeeting" sender:self];
    

    This will only work if the index in viewControllers array matches the one of your view controller and if it exists of course. In this case is the first one (in the array and storyboard).

    The segue ("goToMeeting") must not be attached to an action. The way you do this is by control-dragging from the file owner icon at the bottom of the storyboard scene to the destination scene. A popup will appear that will ask for an option in “Manual Segue”; pick “Push” as the type. Tap on the little square and make sure you’re in the Attributes Inspector. Give it an identifier which you will use to refer to it in code.

    0 讨论(0)
  • 2021-02-20 07:03

    In my case i need to go to dashboard screen from appdelegate using segue, the code as below in objective c.

    if([rememberMe isEqualToString:@"YES"]){
            //Goto Dashboard
            self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            SWRevealViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"revealVc"];
            self.window.rootViewController = vc;
            [self.window.rootViewController performSegueWithIdentifier:@"sw_front" sender:self];
            [self.window makeKeyAndVisible];
        }else{
            //Goto login
            self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            LoginViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
            self.window.rootViewController = vc;
            [self.window makeKeyAndVisible];
        }
    

    Write inside your didFinishLaunchingWithOptions

    Hope it helps some one.

    0 讨论(0)
  • 2021-02-20 07:06

    If you consider pushing view manually rather then segueperform following code most probably will work for you

    - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
        if ([[DBSession sharedSession] handleOpenURL:url]) {
            if ([[DBSession sharedSession] isLinked]) {
    
                NSLog(@"App linked successfully!");
                // At this point you can start making API calls
    
                //push view manually 
                UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
                LoginDropboxViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"LoginDropbox"];
                [(UINavigationController*)self.window.rootViewController pushViewController:ivc animated:NO];
    
    
    
        }
            return YES;
        }
        // Add whatever other url handling code your app requires here
        return NO;
    }
    
    0 讨论(0)
提交回复
热议问题