【问题标题】:Change UITabBarController selected index programmatically not working with 5 tabs以编程方式更改 UITabBarController 选择的索引不适用于 5 个选项卡
【发布时间】:2018-10-22 12:07:24
【问题描述】:

我想以编程方式更改选定的索引,但有时它不起作用;我很确定在标签栏控制器内调用了这些函数。也一起一一测试!

selectedIndex = 1
selectedViewController = viewControllers![1]

我的 TabBarController 包含 5 个选项卡。

【问题讨论】:

  • 确保您没有返回错误的表单 tabbarShouldSelect 委托方法
  • 我还没有实现那个方法。
  • 您是否尝试使用其他索引或其他视图视图控制器正在工作?比如 2 、 3 或 4
  • 也试试这个 tabBar.selectedItem = tabBar.items![1] as UITabBarItem
  • 是的,有时有效,有时无效,甚至似乎与标签索引无关。

标签: ios uitabbarcontroller


【解决方案1】:

试试这个:

对于点击特定按钮的动作:

- (IBAction)IndexBtnActn:(id)sender
{
    [self.tabBarController setSelectedIndex:1] ;
}

【讨论】:

  • 这似乎和我写的没什么区别,而且我使用的是标签栏控制器本身内部的代码,所以不需要self.tabBarController。
猜你喜欢
  • 2016-12-03
  • 2015-05-20
  • 2011-06-12
  • 2015-10-31
  • 1970-01-01
  • 2015-06-01
  • 2021-12-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多