我尝试使用以下片段
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/