如何在AppDelegate中执行Segue? [英] How to perform Segue in AppDelegate?

查看:68
本文介绍了如何在AppDelegate中执行Segue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Storyboard在IOS 5.1上完成一个应用程序。基本上我正在做一个保管箱应用程序。由于我使用的是Dropbox SDK,因此在AppDelegate.m中处理了指向Dropbox的链接。用户可以选择从会话取消链接,然后在不同的View Controller中再次链接。因此,每次用户链接和未链接的应用程序都必须将视图从Appdelegate切换到未连接到rootviewcontroller的视图控制器

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. User has the option of be able to unlink from a session and link again in different View Controllers. So every time user link and unlinked app has to switch view from Appdelegate to a view controller that is unconnected to rootviewcontroller

在原始Dropbox的示例中,Dropbox像以下代码一样处理过渡

In original Dropbox's example Dropbox handled transition like following code

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    if ([[DBSession sharedSession] handleOpenURL:url]) {
        if ([[DBSession sharedSession] isLinked]) {
            [navigationController pushViewController:rootViewController.photoViewController animated:YES];
        }
        return YES;
    }

    return NO;
}

但是我将Storyboard与Navigation Controller一起使用,但以下任何一种方法都不适用

But I am using Storyboard with Navigation Controller and any of the following methods are not working I put methods in comments.

- (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

            /*UIViewController *viewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:NULL] instantiateViewControllerWithIdentifier:@"MeetingViewController"];
            [self.navigationController pushViewController:viewController animated:YES]; */

           //[self performSegueWithIdentifier:@"xxxx" sender:self];

           /* LoginDropboxViewController *loginController=[[LoginDropboxViewController alloc] initWithNibName:@"LoginDropbox" bundle:nil];
            [navigationController pushViewController:loginController animated:YES]; */

        }
        return YES;
    }
    // Add whatever other url handling code your app requires here
    return NO;
}

这是应用程序的故事板

Here is the storyboard of the app

所以我该如何在AppDelegate.h中切换视图?

So how can I switch view in AppDelegate.h ?

注意:如果我添加一个segue并命名该segue,可以说goToMeeting
[self performSegueWithIdentifier:@ goToMeeting sender:self];

Note: If I add a segue and name the segue lets say goToMeeting [self performSegueWithIdentifier:@"goToMeeting" sender:self];

我得到的错误是: AppDelegate没有可见的@interface声明选择器performSegueWithIdentifier:sender

推荐答案

如果您考虑手动推送视图,而不是segueperform,则下面的代码很可能对您有用

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;
}

这篇关于如何在AppDelegate中执行Segue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆