在Tab Bar按下时触发模态视图控制器的最佳方法。

时间:2012-08-31 00:56:31

标签: uiviewcontroller uitabbarcontroller uitabbar uitabbaritem uimodalpresentationstyle

当用户触发标签栏项目时,我想显示一个模态视图控制器。

我有一些工作,但它可能不是最干净的方法。它还可以防止UITabBarItem处于选中状态。

我所做的是将此方法设置为false,并在显示视图控制器的方法体中(通过RootViewController)。

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    UINavigationController *nvc = (UINavigationController*)viewController;

你们有没有想过更清晰的实现,这将允许TabBarItem突出显示?

1 个答案:

答案 0 :(得分:0)

这是在标签栏上使用MVC的方法之一...突出显示标签栏项目。

id currentSelected; //这将保存所选视图的地址 id dontAllowSelection; //这将保留拒绝视图的地址

  • (BOOL)tabBarController:(UITabBarController *)tabBarControllers shouldSelectViewController:(UIViewController *)viewController

{

if(dontAllowSelection!= nil&& //如果它是零,我们将跳过它。          dontAllowSelection == viewController)//如果所选视图被拒绝,则返回NO     {

返回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;

}

相关问题