How to disable multi click on button?

本小妞迷上赌 提交于 2019-12-04 10:48:32

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

Call the below code for pushing to another ViewController

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

You have to set exclusive touch on each cell's button.

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

    // Get your cell

    cell.button.exclusiveTouch = YES;

    return cell;

}

if above method is not working then when one button is clicked you can disable the interaction with the cell

cell.userInteractionEnabled = NO;

Later as per your need or in viewWillAppear enable the same.

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

Also disable the multiple touch property from the tableView

self.tableView.multipleTouchEnabled = NO;

Change your button's IBAction forControllEvent as UIControlEventTouchDown.

if you use storyboard cell hook up your buttons action by changeing touchUpInside to touchDown.

or

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

This will prevent button touch and holding. and this Action will call push immediatly at your touch.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!