如何禁用多点击button?

我有一个UITableView:

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

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

它工作正常。 但是,当我尝试按住并同时按下两个button时,我的应用程序会收到以下警告:

嵌套的推动animation可能会导致导航栏损坏。 完成处于意外状态的导航转换。 导航栏子视图树可能会损坏。

我应该如何禁用单元格上的多点击button?

您只需要禁用button,同时推到另一个视图控制器。 您可以创buildUINavigationController类别,以推送到另一个视图控制器。 确保在返回到当前viewController之前启用该button

 @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

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

您必须设置专门的触摸button

 - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ // Get your cell cell.button.exclusiveTouch = YES; return cell; } 

如果上面的方法不工作,那么当单击一个button时,可以禁用与单元格的交互

 cell.userInteractionEnabled = NO; 

后来根据你的需要或在viewWillAppear启用相同的。

 cell.contentView.exclusiveTouch = YES; cell.exclusiveTouch = YES; 

同时禁用tableView中的多点触控属性

 self.tableView.multipleTouchEnabled = NO; 

将button的IBAction forControllEvent更改为UIControlEventTouchDown。

如果你使用storyboard cell把你的button动作改成touchUpInside touchDown。

要么

 [YOUR_BUTTON addTarget:self action:@selector(YOUR_IBACTION:) forControlEvents:UIControlEventTouchDown]; 

这将防止button触摸和持有。 这一行动将立即通过您的联系立即致电。