取消在我的导航控制器中单击后退按钮

发布于 2024-10-21 01:25:11 字数 1383 浏览 1 评论 0原文

我有一个自定义的 navigationController :

#import "customNavigationController.h"
#import "StartViewController.h"
#import "EtapeViewController.h"

@implementation customNavigationController

- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
    // Accueil du guide, on cache le navigationBar
    if([self.viewControllers count] == 2){
        self.navigationBarHidden = TRUE;
        return [super popViewControllerAnimated:animated];
    }
    // Si on est pas à l'accueil, on fait l'action normal sur le backBarButton
    else {
        // Si on est dans une étape, le backButton va servir à reculer dans les étapes, et non reculer vers le workflow
        NSString *className = NSStringFromClass([[self.viewControllers objectAtIndex:[self.viewControllers count] - 1] class]);
        if ([className isEqualToString:@"EtapeViewController"]) {
            EtapeViewController *etape = [self.viewControllers objectAtIndex:[self.viewControllers count] - 1];
            if (etape.show_previous_button) {
                [etape previousEtape:nil];
                return FALSE;
            }
            return [super popViewControllerAnimated:animated];
        }
        else {
            return [super popViewControllerAnimated:animated];
        }
    }
}
@end

在某些情况下,我想取消 backButton 的单击事件(在显示“return FALSE”的行上),但它不起作用。

有办法做到吗?

I have a custom navigationController :

#import "customNavigationController.h"
#import "StartViewController.h"
#import "EtapeViewController.h"

@implementation customNavigationController

- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
    // Accueil du guide, on cache le navigationBar
    if([self.viewControllers count] == 2){
        self.navigationBarHidden = TRUE;
        return [super popViewControllerAnimated:animated];
    }
    // Si on est pas à l'accueil, on fait l'action normal sur le backBarButton
    else {
        // Si on est dans une étape, le backButton va servir à reculer dans les étapes, et non reculer vers le workflow
        NSString *className = NSStringFromClass([[self.viewControllers objectAtIndex:[self.viewControllers count] - 1] class]);
        if ([className isEqualToString:@"EtapeViewController"]) {
            EtapeViewController *etape = [self.viewControllers objectAtIndex:[self.viewControllers count] - 1];
            if (etape.show_previous_button) {
                [etape previousEtape:nil];
                return FALSE;
            }
            return [super popViewControllerAnimated:animated];
        }
        else {
            return [super popViewControllerAnimated:animated];
        }
    }
}
@end

In some case, I want to cancel the click event of the backButton (on the line that reads "return FALSE"), but it doesn't work.

Is there a way to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ぺ禁宫浮华殁 2024-10-28 01:25:11

您可以执行以下操作来代替 return FALSE

return nil;

或者

return [self topViewController];

Either 应该具有正确的副作用。

话虽这么说,请小心您的 UI 设计。确保用户知道后退按钮不起作用的原因。

in place of return FALSE, you can do:

return nil;

or

return [self topViewController];

Either should have the right side effect.

That being said, be careful with your UI design here. Make sure the user knowns why the back button doesn't work somehow.

等待圉鍢 2024-10-28 01:25:11

在您不希望用户点击后退按钮的情况下,为什么不禁用后退按钮呢?

Why don't you disable the back button in the situations that you don't want the user to tap it?

时间海 2024-10-28 01:25:11

我不明白为什么要让“后退”按钮忽略点击?这似乎会让用户感到困惑,App Store 团队会认为这是一个错误。也许您可以发布屏幕截图?

重新设计界面并考虑 1) 使用工具栏按钮进行导航(如 Mobile Safari)或 2) 完全支持基于 UINavigation 的视图而不是解决它可能会更好。


更新:听起来您要执行不同的操作,例如显示确认?我不知道有什么官方方法可以完成您想要的操作,因为 UINavigationControllerDelegate 方法只是通知您有关转换的信息,它们不允许您取消/修改它们。 (如果过渡是动画的,那么使用导航控制器的视图堆栈可能不会有帮助。)

因此,您始终可以在后退按钮上浮动一个透明(或几乎透明)的窗口,并以这种方式拦截点击。以下是一些与状态栏执行类似操作的示例栏:

https://github.com/myell0w/MTStatusBarOverlay

I don't understand why you would make the Back button ignore taps? It seems like this would confuse users and the App Store team would consider this a bug. Perhaps you could you post a screenshot?

It would probably be better to redesign your interface and consider 1) using toolbar buttons for navigation (like Mobile Safari) or 2) fully support UINavigation based views rather than working around it.


Update: It sounds like you're going to perform a different action, like displaying a confirmation? I don't know of any official ways to do what you want, since the UINavigationControllerDelegate methods just notify you about transitions, they don't let you cancel/modify them. (And if the transition is animated then playing with the navigation controller's view stack probably won't help.)

So you could always float a transparent (or almost transparent) window over the back button and intercept taps that way. Here's some sample bar that does something similar with the status bar:

https://github.com/myell0w/MTStatusBarOverlay

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文