0

我正在尝试加载具有多个视图的选项卡栏,但我希望只有在用户具有权限的情况下才打开几个选项卡。是否有任何代表电话可以处理这个问题?我在 tabbardelegate 中查看了它只有 didSelectItem 不像文本字段有 bool 用于返回文本,所以我选择返回或不返回。

谢谢

4

1 回答 1

1

你可以使用- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item你讨论过的。

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    if (item == 2 || item == 3) { //Tab 2 and 3 are protected
        if (!userHasPermission) {
            tabBar.selectedItem = 0; //Make user go to first tab if the user does not have permission.
        }
    }
}

或者,如果您希望禁用某些项目。在你的-viewDidLoad

if (!userHasPermission) {
    UITabBarItem *tabBarItem = [[myTabBar items] objectAtIndex:2];
    [tabBarItem setEnabled:NO];
}
于 2012-09-11T14:56:53.407 回答