ios - UITabbarController - 如何取消选择 iOS 5.0 和 iOS 4.3 中的所有选项卡

标签 ios uitabbarcontroller

我尝试使用以下片段

DefaultView *defaultView = [[DefaultView alloc]initWithNibName:@"DefaultView" bundle:[NSBundle mainBundle]];
        [self.tabBarController setSelectedViewController:nil];
        [self.tabBarController setSelectedViewController:defaultView];

它适用于 iOS 4.3 及以下版本,但在 iOS 5.0 上会出现以下错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController setSelectedViewController:] only a view controller in the tab bar controller's list of view controllers can be selected.'

关于在 iOS 5.0 中应该做什么来解决这个错误的任何线索?

最佳答案

DefaultView 是您的选项卡之一?如果是,请尝试选择它:

NSUInteger newIndex = [self.tabBarController.viewControllers indexOfObjectIdenticalTo:defaultView];
[self.tabBarController setSelectedIndex:newIndex];

不知道是不是你所期望的,也许是更多的信息?

编辑:您收到此错误是因为:只能选择选项卡栏 Controller 的 View Controller 列表中的 View Controller 。这意味着默认 View 不在您的 View 列表中,因此您无法选择它。

关于ios - UITabbarController - 如何取消选择 iOS 5.0 和 iOS 4.3 中的所有选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8075207/

相关文章:

swift - 如何使用 Swift 显示工具栏按钮并将其添加到 UITableViewController

iOS 有边框按钮点击时的行为

ios - 无法从模态 ViewController 访问 UITabBarController

ios - 导航到第二个 View Controller 时选项卡栏隐藏

iphone - 如何在 UINavigationController 和 UITabBarController 内翻转 View (使用 UIModalTransitionStyleFlipHorizo​​ntal)

ios - 需要同时发出两个 HTTP 网络请求(完成处理程序一旦完成)

ios - 无法将内容附加到数组

ios - 当第一个字母按下 UISearchBar 字段时,UISearchbar 消失,iOS7

ios - SpriteKit - SKLightNode 阴影混合模式

ios - 如何在不丢失选项卡的情况下在选项卡式应用程序上加载另一个 View Controller