0

我有以下链接中出现的相同问题

如何从 UIButton 到选项卡栏项?

不幸的是,到目前为止我找不到任何解决方案

备注:

1) 我正在使用带有情节提要的 iOS 5 - 如果有所作为 -

2)我试过[self.tabBarController.tabBar setSelectedItem:[self.tabBarController.tabBar.items objectAtIndex:3]];了,但它也不起作用

3)我尝试为标签栏设置IBOutlet并直接访问它,但是当我调用时应用程序崩溃[self.myTabbar setSelectedItem:[self.myTabbar.items objectAtIndex:3]];并出现此错误:不允许直接修改由标签栏控制器管理的标签栏

在此处输入图像描述

4

2 回答 2

18

OMG,这就像一个魔术,解决方案是:

[(UITabBarController*)self.navigationController.topViewController setSelectedIndex:3];

我从以下帖子中获得了解决方案: https ://stackoverflow.com/a/10533414/1150618

于 2012-08-07T13:01:16.047 回答
4

从一个tabBarItem地方开始AppDelegate

[(UITabBarController *) self.window.rootViewController setSelectedIndex: 2];

所以RootViewController自动启动viewController

于 2015-01-09T17:40:02.010 回答