2012-09-06 48 views
10

我正在嘗試在Storyboard上完成IOS 5.1上的應用程序。基本上我正在做一個Dropbox應用程序。由於我使用Dropbox SDK鏈接到Dropbox,因此在AppDelegate.m中處理。用戶可以選擇從會話中取消鏈接,並在不同的視圖控制器中重新鏈接。所以每次用戶鏈接和未連接的應用程序必須從AppDelegate中切換視圖到視圖控制器未連接到RootViewController的如何在AppDelegate中執行Segue?

在原來的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; 
} 

過渡,但我現在用故事板與導航控制器和以下任何方法都無法正常工作我將方法放在註釋中。

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

這裏是應用 enter image description here

所以,我怎麼可以切換視圖AppDelegate.h的故事板?

注意:如果我添加一個segue並命名segue讓我們說goToMeeting [self performSegueWithIdentifier:@「goToMeeting」sender:self];

錯誤我得到的是:No Visible @interface for 'AppDelegate' declares the selector performSegueWithIdentifier:sender

回答

12

如果考慮推視圖中手動而不是segueperform下面的代碼很可能會爲你

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

工作,你可以做這樣的:

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

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

這隻有在viewControllers數組中的索引匹配您的視圖控制器中的索引以及它當然存在時纔有效。在這種情況下是第一個(在數組和故事板中)。

不得將segue(「goToMeeting」)附加到某個操作。你這樣做的方式是通過控制 - 從故事板場景底部的文件所有者圖標拖動到目標場景。將出現一個彈出窗口,要求在「手動塞格」中選擇一個選項;選擇「推」作爲類型。點擊小方塊並確保你在屬性檢查器中。給它一個你將用來在代碼中引用它的標識符。

+3

但是,如果我需要將參數數據傳遞給performSegueWithIdentifier調用,我該怎麼辦。在應用程序委託沒有ViewController,所以我不能覆蓋prepareForSegue()調用? – ChaosSpeeder