如何禁用多按钮?

时间:2015-05-15 04:45:22

标签: ios objective-c uitableview multi-touch

我有一个UITableView:

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

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

工作正常。但是,当我尝试同时按住两个按钮时,我的应用会收到 跟随 警告:

  

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

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

5 个答案:

答案 0 :(得分:4)

您只需要在推送到另一个View Controller时禁用该按钮。 您可以创建UINavigationController类别以推送到另一个视图控制器。确保在返回当前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

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

答案 1 :(得分:1)

您必须在e ach cell的按钮上设置独家触摸

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    // Get your cell

    cell.button.exclusiveTouch = YES;

    return cell;

}

答案 2 :(得分:0)

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

还禁用tableView

中的多重触摸属性
self.tableView.multipleTouchEnabled = NO;

答案 3 :(得分:0)

如果上述方法不起作用,那么当单击一个按钮时,您可以禁用与单元格的交互

cell.userInteractionEnabled = NO;

根据您的需要或viewWillAppear启用相同功能。

答案 4 :(得分:0)

将按钮的IBAction forControllEvent更改为UIControlEventTouchDown。

如果您使用故事板单元格 通过将touchUpInside更改为touchDown来连接您的按钮操作。

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

这将阻止按钮触摸和保持。并且这个动作将立即通过你的方式调用push。

相关问题