11

Storyboardを使用してIOS5.1でアプリケーションを完成させようとしています。基本的に私はドロップボックスアプリをやっています。Dropbox SDKを使用しているため、DropboxへのリンクはAppDelegate.mで処理されます。ユーザーは、セッションからリンクを解除して、別のViewControllerで再度リンクできるようにするオプションがあります。したがって、ユーザーリンクとリンクされていないアプリがビューをAppdelegateからrootviewcontrollerに接続されていないViewControllerに切り替える必要があるたびに

元のDropboxの例では、Dropboxは次のコードのように遷移を処理しました

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

しかし、Navigation ControllerでStoryboardを使用していて、次のメソッドのいずれかが機能していません。コメントにメソッドを入れました。

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

これがアプリのストーリーボードです ここに画像の説明を入力してください

では、AppDelegate.hでビューを切り替えるにはどうすればよいですか?

注:セグエを追加してセグエに名前を付けると、goToMeeting [self PerformSegueWithIdentifier:@ "goToMeeting" sender:self];と言うことができます。

私が得るエラーは:No Visible @interface for 'AppDelegate' declares the selector performSegueWithIdentifier:sender

4

3 に答える 3

13

ビューを手動でプッシュするのではなく手動でプッシュすることを検討している場合は、次のコードを実行することでおそらくうまくいくでしょう

- (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;
}
于 2012-09-10T20:13:56.517 に答える
5

あなたはこのようにそれを行うことができます:

UINavigationController *navigationController = (UINavigationController*) self.window.rootViewController;

[[[navigationController viewControllers] objectAtIndex:0] performSegueWithIdentifier:@"goToMeeting" sender:self];

これは、viewControllers配列のインデックスがView Controllerのインデックスと一致し、もちろん存在する場合にのみ機能します。この場合は(アレイとストーリーボードの)最初のものです。

セグエ( "goToMeeting")をアクションにアタッチしてはなりません。これを行う方法は、ストーリーボードシーンの下部にあるファイル所有者アイコンから宛先シーンにコントロールドラッグすることです。「手動セグエ」のオプションを尋ねるポップアップが表示されます。タイプとして「プッシュ」を選択します。小さな四角をタップして、属性インスペクターにいることを確認します。コードで参照するために使用する識別子を指定します。

于 2014-04-01T22:46:36.033 に答える
0

私の場合、セグエを使用してappdelegateからダッシュボード画面に移動する必要があります。以下のコードはObjectivecにあります。

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

あなたの中に書いてくださいdidFinishLaunchingWithOptions

それが誰かを助けることを願っています。

于 2019-08-06T07:31:29.550 に答える