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

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

问题描述

我想在用户点击标签栏项目时禁用默认操作.

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 对象有同样的问题,第二次按下已经显示的联系人"选项卡会使 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'

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

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