Target action is called twice

ios, iphone, objective-c

Solution

`UIButton` generates multiple events while pressing: usually they are `UIControlEventTouchDownInside` and `UIControlEventTouchUpInside`. So, if you want to handle press, you should catch the one you need (probably `UIControlEventTouchUpInside`), not `UIControlEventsAll`.

Problem

I have a VC RaceDayChecklistViewController.m which is subclass of RaceDayChecklistViewControllerBase.m. In RaceDayChecklistVC.m , added a target action which is getting called twice. nextOrNewButton is the button on click of which i want to invoke "demo" action. Also ,checklistnavigationItem is the bar Button item. ``` - (void)viewDidLoad { checklistTableViewBase=checklistTableView; checklistNavigationItemBase=checklistnavigationItem; nextOrNewButtonBase=nextOrNewButton; [nextOrNewButton addTarget:self action:@selector(demo) forControlEvents:UIControlEventAllEvents]; } -(void) demo { RaceDayDataController *sharedController = [RaceDayDataController sharedDataController]; if (sharedController.isSubmited) { [self.checklistnavigationItem setTitle:@"New"]; // } else { [self.checklistnavigationItem setTitle:@"Next"]; [self showAlert]; } } -(void) viewWillDisappear:(BOOL)animated { [nextOrNewButton removeTarget:self action: @selector(demo) forControlEvents:UIControlEventAllEvents]; } ``` What could be the reason for multiple call to the action demo? Is it the base class responsible some how? pls guide.

Original source

Related problems