【问题标题】:Best way to trigger a Modal View Controller on Tab Bar press.在 Tab Bar 按下时触发模态视图控制器的最佳方式。
【发布时间】:2012-08-31 00:56:31
【问题描述】:

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

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

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

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

你们有什么更简洁的实现方法可以让 TabBarItem 突出显示吗?

【问题讨论】:

    标签: uiviewcontroller uitabbarcontroller uitabbar uitabbaritem uimodalpresentationstyle


    【解决方案1】:

    这是在 Tab bar 上使用 MVC 的一种方法......像这样突出显示标签栏项目。

    id 当前选择; //这将保存所选视图的地址 id 不允许选择; //这将保存拒绝视图的地址

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

    {

    if (dontAllowSelection != nil && //如果为nil,我们将跳过它。 dontAllowSelection == viewController) //如果选择的视图被拒绝返回 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;
    

    }

    【讨论】:

    • 不确定你在做什么。标识符很乱
    猜你喜欢
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-06
    • 2020-02-07
    • 1970-01-01
    相关资源
    最近更新 更多