禁用操作 - 用户点击标签栏项目以转到根视图控制器

2023-06-11移动开发问题
0

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

问题描述

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

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'

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

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7