tabbar的iphone应用程序

时间:2011-04-22 05:33:41

标签: iphone

如何定义和检查hasSelectedSpecificTab和viewControllerNotToAllow 我的应用程序。有人给我一个例子。

我想做点什么。喜欢。选择第二个选项卡时,如果未选择第二个选项卡,则仅选择剩余选项卡。

这就是我使用以下代码的原因。

请回复

- (BOOL)tabBarController:(UITabBarController *)tabBarControllers shouldSelectViewController:(UIViewController *)viewController
{
if(alreadySelectedSpecificTab)
        {
             if([viewController isEqual:viewControllerNotToAllow])
                  return NO;
        }
        return YES;
}

1 个答案:

答案 0 :(得分:0)

在班级中创建一些属性

并跟踪你想要拒绝的内容以及你不想拒绝的内容。

id currentlySelected; //This will hold the address of the selected view
id dontAllowSelection; //This will hold the address of the Denied view


- (BOOL)tabBarController:(UITabBarController *)tabBarControllers shouldSelectViewController:(UIViewController *)viewController
{
    if (dontAllowSelection != nil &&             //If it is nil, we will skip it.
         dontAllowSelection == viewController)   //If the selected view is Denied return NO
    {
        return NO;
    }
    currentlySelected = viewController;

    if (currentlySelected == someViewIWantToDisableOtherFor) //Any logic can go here to enable the Denied View.
    {
        dontAllowSelection = anotherViewIWantDisabled; //Set my denied view.
    }
    else
    {
        dontAllowSelection = nil; //Unsed the Denial.
    }

    return YES;
}