我有一个使用 6.1 base sdk 构建的 iOS 应用程序。现在我将应用程序移动到下一个 SDK 7.0。我有一个标签栏,上面有 5 个项目。每个选项卡都是一个导航 Controller 。此外,每个被插入这些导航 Controller 的 View Controller 都使用方法隐藏标签栏
[self setHidesBottomBarWhenPushed:YES];
当我在第二个选项卡时,我按下一个按钮,在网络连接后,它会弹出到 Root View Controller 并更新 tabbarcontroller 的 selectedIndex。主标签栏 Controller 通过其在 appdelegate 中的引用来访问。 The thing happening is when selected index is 1 and then I set it as 2 the tab bar disappears.但是,当它是 2 时,我再次将它设置为 2 就没有问题了。
[self.application.tabBarController setSelectedIndex:2];
此问题仅出现在 iOS 7 模拟器中。当我在 iOS 6 模拟器上模拟时,它没有发生。我的标签栏项目也是自定义的,我不知道是否与它有关。
可能是什么问题?
最佳答案
我找到了解决方案。一开始我的代码如下。标签栏 Controller 中的两个导航 Controller 都弹出到 Root View Controller 。
[self.navigationController popToRootViewControllerAnimated:YES];
[self.application.tabBarController setSelectedIndex:2];
[self.application.tabBarController.secondTabNavigationController popToRootViewControllerAnimated:YES];
当我重新排列 popToRootViewController 方法的顺序时,问题就消失了。
[self.application.tabBarController setSelectedIndex:2];
[self.application.tabBarController.secondTabNavigationController popToRootViewControllerAnimated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
第一个在 iOS 6 设备上运行良好,但在 iOS 7 设备上运行不正常。第二个适用于所有人。
关于ios - 当 iOS 7 上的 selectedIndex 值改变时 TabBar 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21681185/