在 iOS 5 中取消选择或取消选择标签栏中的所有标签

人气:870 发布:2022-10-16 标签: ios5 unselect uitabbarcontroller uitabbar uitabbaritem

问题描述

我是 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];

501