禁用操作 - 用户点击tabbar项目以转到根视图控制器 [英] Disable action - user taps on tabbar item to go to root view controller

查看:107
本文介绍了禁用操作 - 用户点击tabbar项目以转到根视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户点击tabbar项时禁用默认操作。

I want to disable the default action when user taps the tabbar item.

例如,我有一个带有Tab1,Tab2和Tab3的标签栏。在Tab1中,用户可以从View1导航到View3(View1> View2> View3)。如果用户在View3,并且他点击Tab1,则应用程序将用户带到View1(根视图控制器)。我想禁用此功能。我不希望在Tab1上点击以弹出所有视图控制器。我怎么能这样做?

For example, i have a tabbar with Tab1, Tab2 and Tab3. In Tab1, user can navigate from View1 to View3 (View1 > View2 > View3). If user is at View3, and he taps the Tab1, the application takes the user to View1 (the root view controller). I want to disable this functionality. I don't want the tap on Tab1 to pop all the view controllers. How can i do that?

编辑:

这个行为有点儿奇怪,但是在深层次结构的情况下是一个方便的快捷方式!

This behavior is a little strange, but a handy shortcut in case of deep hierarchy!

您可以实现以下UITabBarControllerDelegate方法来禁用此系统范围的快捷方式:

You can implement following UITabBarControllerDelegate methods to disable this system wide shortcut:

#pragma mark -
#pragma mark UITabBarControllerDelegate

- (BOOL)tabBarController:(UITabBarController *)tbc shouldSelectViewController:(UIViewController *)vc {
    UIViewController *tbSelectedController = tbc.selectedViewController;

    if ([tbSelectedController isEqual:vc]) {
        return NO;
    }

    return YES;
}


推荐答案

如果你看一下UITabBarController委派有如下方法:

if you look at the UITabBarController delegate there is a method:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

如果你在类中实现了这个,你可以检查UIViewController是否已经显示,然后返回NO ,这将阻止这种情况发生。

If you implement this in your class, you can check if the UIViewController is the already displayed one and then return NO, which will stop this from happening.

我在UITabBarController中嵌入的ABPeoplePicker对象遇到了同样的问题,因为第二次按下Contacts选项卡已经显示了ABPeoplePicker控件显示'群组'

I had the same problem with a ABPeoplePicker object embedded in a UITabBarController, in that pressing the 'Contacts' tab a second time which was already displayed would make the ABPeoplePicker control show the 'Groups'

这篇关于禁用操作 - 用户点击tabbar项目以转到根视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆