如何禁用多按钮? [英] How to disable multi click on button?

查看:147
本文介绍了如何禁用多按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView:

I have a UITableView:

单元格1: 按钮1->按下以查看控制器A

单元格2: 按钮2->按下以查看控制器B

一切正常。但是,当我尝试同时按住两个按钮时,我的应用会收到 以下 警告:

It works fine. However, when I try to hold and press two buttons at the same time, my app receives following warning:


嵌套推送动画可能导致导航栏损坏。
在意外状态下完成导航过渡。
导航栏子视图树可能已损坏。

nested push animation can result in corrupted navigation bar. Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

如何禁用单元格上的多点击按钮?

How should I disable multi click button on cell ?

推荐答案

您只需要在推送到另一个View Controller时禁用该按钮。
您可以创建 UINavigationController 的类别,以便推送到另一个视图Controller。确保在返回当前viewController之前启用该按钮

You just need to disable the button while pushing to another View Controller. You can create category ofUINavigationController for pushing to another view Controller. Make sure that you enable the button before coming back to current viewController

@interface UINavigationController (CompletionHandler)

- (void)pushViewController:(UIViewController *)viewController
              animated:(BOOL)animated
            completion:(void (^)(void))completion;

@end




@implementation UINavigationController (CompletionHandler)
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(void (^)(void))completion {
[CATransaction begin];
[CATransaction setCompletionBlock:completion];
[self pushViewController:viewController animated:animated];
[CATransaction commit];
}


@end

致电下面的代码推送到另一个ViewController

Call the below code for pushing to another ViewController

[self.navigationController pushViewController:ControllerObj animated:YES completion:^{
        btn.userInteractionEnabled = NO; // Your Button Object
        NSLog(@"COMPLETED");
    }];

这篇关于如何禁用多按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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