开发者

iPhone programmatically select Tab AND push view controller

With Facebook's new SSO, logging into Facebook means that my app is temporarily shut down. The problem is that my app requirements dictate that it cannot run in the background. So, when my app is brought back up, it is on the original tab/view controller.

I am trying to get things back to the facebook login view. This requires programmatically selecting a tab AND pushing from that tab to a separate view controller.

I can programmatically select a tab no problem:

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

But I cannot push the view controller from the newly selected tab. I've tried

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

and

AboutViewController *nextViewController = [[AboutViewController alloc] initWithStyle:UITableViewStyleGrouped];
    ((AboutViewController *)nextViewController).hidesBottomBarWhenPushed = NO;
    [[[[[UIApplication sharedDelegate] tabBarController] navigation开发者_如何转开发Controller] pushViewController:nextViewController animated:NO];
    [nextViewController release];

Is it even possible to do this?


try this:

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


Here is a Swift solution if anyone needs it:

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

In my case, had to get from a nested viewController in tab 2 to another nested view controller in tab 4.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜