iPhone以编程方式选择Tab AND推视控制器

时间:2011-10-14 07:07:02

标签: iphone facebook-graph-api single-sign-on tabbar pushviewcontroller

使用Facebook的新SSO,登录Facebook意味着我的应用暂时关闭。问题是我的应用程序要求规定它不能在后台运行。因此,当我的应用程序重新启动时,它位于原始选项卡/视图控制器上。

我正在努力让事情回到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];

甚至可以这样做吗?

2 个答案:

答案 0 :(得分:6)

试试这个:

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

答案 1 :(得分: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中的另一个嵌套视图控制器。