3

使用Facebook的新SSO登錄到Facebook意味着我的應用暫時關閉。問題是我的應用程序需求決定它不能在後臺運行。所以,當我的應用程序恢復時,它在原始選項卡/視圖控制器上。iPhone以編程方式選擇標籤並推送視圖控制器

我想讓事情回到facebook登錄視圖。這需要以編程方式選擇一個選項卡並從該選項卡推送到單獨的視圖控制器。

我可以編程選擇一個標籤沒有問題:

[[UIApplication sharedDelegate].tabBarController setSelectedIndex:4]; 

但我不能從該新選擇的選項卡推視圖控制器。我試過

AboutViewController *nextViewController = [[AboutViewController alloc] initWithStyle:UITableViewStyleGrouped]; 
    ((AboutViewController *)nextViewController).hidesBottomBarWhenPushed = NO; 
    [[[[[UIApplication sharedDelegate] tabBarController] selectedViewController ] navigationController] pushViewController:nextViewController animated:NO]; 
    [nextViewController release]; 

AboutViewController *nextViewController = [[AboutViewController alloc] initWithStyle:UITableViewStyleGrouped]; 
    ((AboutViewController *)nextViewController).hidesBottomBarWhenPushed = NO; 
    [[[[[UIApplication sharedDelegate] tabBarController] navigationController] pushViewController:nextViewController animated:NO]; 
    [nextViewController release]; 

它甚至有可能做到這一點?

回答

6

試試這個:

AboutViewController *nextViewController = [[AboutViewController alloc] initWithStyle:UITableViewStyleGrouped]; 
[[self.tabBarController.viewControllers objectAtIndex:4] pushViewController: nextViewController animated:NO]; 
[nextViewController release]; 
+1

工作!但首先我必須調用[tabBarController setSelectedIndex:4];謝謝! – SAHM

0

這裏是一個Swift解決方案,如果有人需要它:

func goToHelpViewController(){ 
       dispatch_async(dispatch_get_main_queue(), {() -> Void in 
        self.tabBarController?.selectedIndex = 3 
        let settingsStoryBoard = UIStoryboard(name: "SettingsSection", bundle: nil) 
        let helpViewController = settingsStoryBoard.instantiateViewControllerWithIdentifier("HelpViewController") as! HelpViewController 
        let settingsRootNavigationController = self.tabBarController?.viewControllers![3] as! UINavigationController 

      settingsRootNavigationController.popToRootViewControllerAnimated(false) 
        settingsRootNavigationController.pushViewController(helpViewController, animated: true) 
       }) 
      } 

在我的情況下,曾在片2,從嵌套的viewController到達另一個嵌套的視圖控制器在標籤4中。

相關問題