在 iOS 5 中取消选择或取消选择标签栏中的所有标签 [英] Deselect or unselect all tabs in tabbar in iOS 5

查看:25
本文介绍了在 iOS 5 中取消选择或取消选择标签栏中的所有标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 iOS 开发的新手,我直接从 IOS 5 开始.我创建了一个故事板,其中包含一个 tabview 控制器作为它的 rootviewcontroller.我在上面放了 2 个标签.

I am new to iOS development and I have started with IOS 5 directly. I have created a storyboard which consists of a tabview controller as its rootviewcontroller. I have put 2 tabs to it.

我最初想取消选择/取消选择所有选项卡.我该怎么做呢?我已经尝试了以下

I want to deselect/unselect all the tabs initially. How do I do this? I have tried the following

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

我在其中添加了一个带有标识符view"的视图.

where I have added a view with identifier "view".

但这不起作用,它给出了错误:

But this didn't work, it gives error:

 unrecognized selector sent to instance

我也尝试了以下

[self.tabBarController.tabBar setSelectedItem:nil];

但它说

'NSInternalInconsistencyException', reason: '不允许直接修改由标签栏控制器管理的标签栏.'

'NSInternalInconsistencyException', reason: 'Directly modifying a tab bar managed by a tab bar controller is not allowed.'

我已经在控制器中为第一个选项卡尝试了此代码.我想这样做是因为我想在第一个选项卡视图的顶部放置一个默认视图,并在单击下面的任何选项卡后将其隐藏.

I have tried this code in controller for the first tab. I want to do this because I want to put a default view on top of first tab view and hide it once the use is clicked on any of the tabs below.

推荐答案

我用这个来清除所有选中的tabBarItems

I use this to clear any selected tabBarItems

[myTabBar setSelectedItem:nil];

这篇关于在 iOS 5 中取消选择或取消选择标签栏中的所有标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆