【问题标题】:NavigationController on TabBarItemTabBarItem 上的 NavigationController
【发布时间】:2011-06-12 15:32:28
【问题描述】:

我有一个包含 3 个项目的 tabBarController。

在我的 tabBar 第一项的第一个视图中,我有一个 tableview 和一个 navigationController。

当我在我的 tabBar 的第一个项目中的 tableview 中推 1 行时,如何进入我的 tabBar 的第二个项目?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


Second *two = [[Second alloc] initWithNibName:@"Second" bundle:nil];


[self.navigationController pushViewController:two animated:YES];

[two release];

谢谢

【问题讨论】:

    标签: iphone objective-c ios uinavigationcontroller uitabbarcontroller


    【解决方案1】:

    使用 UITabBarController 上的 selectedIndex 属性。更多信息可以在UITabBarController Class Reference找到。

    self.tabBarController.selectedIndex = 1;
    

    或使用

    [self.tabBarController setSelectedIndex:1];
    

    请注意,索引从 0 开始,因此第二个选项卡位于索引 1。

    【讨论】:

    • 好的,如果我这样做没有任何改变:- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Second *two = [[Second alloc] initWithNibName:@"Second"捆绑:无]; chatView.tabBarController.selectedIndex = 1 ; [self.navigationController pushViewController:两个动画:YES]; 【二次发布】;
    • @XcodeMania:我无法读取未格式化的代码。好吧,我可以有相当的耐心,但是如果您希望我阅读它,请将代码格式化为代码。另外,您没有正确调用它。请参阅上面的编辑。
    【解决方案2】:

    当一个视图控制器被推入另一个 tabBarItem 的导航控制器堆栈时,自动选择一个 tabBarItem 并不是一个好习惯。如果您希望 Second 视图位于第二个选项卡中,则应将该视图控制器添加到第二个选项卡中。

    【讨论】:

      猜你喜欢
      • 2010-12-05
      • 1970-01-01
      • 2012-09-20
      • 2017-09-01
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-15
      相关资源
      最近更新 更多