TienLe
TienLe

Reputation: 623

How to disable multi click on button?

I have a UITableView:

Cell 1: Button 1->push to view controller A

Cell 2: Button 2->push to view controller 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 ?

Upvotes: 4

Views: 2222

Answers (5)

Rakesh Kumar
Rakesh Kumar

Reputation: 81

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");
    }];

Upvotes: 4

abhishekkharwar
abhishekkharwar

Reputation: 3529

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;

}

Upvotes: 1

Britto Thomas
Britto Thomas

Reputation: 2120

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.

Upvotes: 0

Utsav Parikh
Utsav Parikh

Reputation: 1206

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

Also disable the multiple touch property from the tableView

self.tableView.multipleTouchEnabled = NO;

Upvotes: 0

Shruti
Shruti

Reputation: 1849

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.

Upvotes: 0

Related Questions