iPhone以编程方式选择Tab并推送视图控制器

发布于 2024-12-09 13:04:06 字数 1154 浏览 1 评论 0原文

使用 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];

是否有可能做到这一点?

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] navigationController] pushViewController:nextViewController animated:NO];
    [nextViewController release];

Is it even possible to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

≈。彩虹 2024-12-16 13:04:06

试试这个:

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

try this:

AboutViewController *nextViewController = [[AboutViewController alloc] initWithStyle:UITableViewStyleGrouped]; 
[[self.tabBarController.viewControllers objectAtIndex:4] pushViewController: nextViewController animated:NO]; 
[nextViewController release];
じее 2024-12-16 13:04:06

如果有人需要的话,这里有一个 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 中的嵌套视图控制器到达选项卡 4 中的另一个嵌套视图控制器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文