取消选择或取消选择iOS 5中tabbar中的所有选项卡
我是iOS开发新手,我已经直接从IOS 5开始。我创建了一个由tabview控制器作为其rootview控制器的故事板。我已经把2个标签。取消选择或取消选择iOS 5中tabbar中的所有选项卡
我想先取消/取消选择所有选项卡。我该怎么做呢?我已经尝试了以下内容
UIView *view = [[UIView alloc]initWithNibName:@"view" bundle:[NSBundle mainBundle]];
[self.tabBarController setSelectedViewController:nil];
[self.tabBarController setSelectedViewController:view];
其中我添加了一个标识符为“view”的视图。
但这并没有工作,它给了错误:
unrecognized selector sent to instance
我也试过以下
[self.tabBarController.tabBar setSelectedItem:nil];
但它说
'NSInternalInconsistencyException', reason: 'Directly modifying a tab bar managed by a tab bar controller is not allowed.'
我曾尝试在此代码第一个选项卡的控制器。我想这样做是因为我想在第一个选项卡视图顶部放置一个默认视图,并在下面的任何选项卡上单击使用后将其隐藏。
我用它来清除任何选择tabBarItems
[myTabBar setSelectedItem:nil];
老问题。仅用于记录,如果选项卡栏由TabBarController管理,则无法取消选择所有选项卡。方法:
[self.tabBar setSelectedItem:nil];
作品只有如果标签栏不从标签栏控制器来管理。如果是,则无法取消选择所有选项卡,必须始终选择一个选项卡。
我发现了一个解决方案,可能不是最好的方法去解决它,但它对我有用([self.tabBar setSelectedItem:nil];没有)。我把我的标签视图的父视图(myTabBarViewContainer),然后当我想取消我的项目我打电话removeFromSuperview父视图并重新初始化它:
[self.myTabBarViewContainer.view removeFromSuperview];
然后重新初始化它,瞧!
不是很漂亮,但它的作品...
这是一个小hoakey。但是当我想让它看起来没有选择时,我只需将-viewWillAppear中的色调设置为灰色,然后在我想显示选择时将色调颜色设置回“选定”的颜色。
// since we cant turn off tabbar selection, change the color to make
// it look like nothing was selected.
self.tabBarController.tabBar.tintColor = [UIColor grayColor];
-----------
// make sure tintcolor is turned on (just in case another module turned it off
self.tabBarController.tabBar.tintColor = self.view.tintColor;
您应该需要使用UITabBar。不是的UITabBarController
取消或取消的TabBar项目SWIFT 3.0
tabbar_Main.selectedItem = nil
任何方式设置动画? – 2014-11-10 12:59:42