Reputation: 389
In my application I am using custom table cell, in that cell I am having a button.
When I click that button it has to open a popup menu.
if ([strUserID isEqualToString:_LoginID]){
[cell.editButton addTarget:self action:@selector(myoptionsmenu:) forControlEvents:UIControlEventTouchUpInside];
} else {
[cell.editButton addTarget:self action:@selector(otheroptionsmenu:) forControlEvents:UIControlEventTouchUpInside];
}
This is working fine. For login user post, the menu will be myoptionsmenu:
For other users post, the menu will be otheroptionsmenu:
First when I click myoptionsmenu: it is working fine, second when I click otheroptionsmenu: it is working fine.
In the third post, when I click it is showing both myoptionsmenu: and otheroptionsmenu: menus.
I would like to know how to avoid this.
Upvotes: 0
Views: 729
Reputation: 499
If the cell hasn't changed between the calls, then you've probably added multiple targets to the same button.
It isn't clear from your post how you created the cells or buttons and what code is being executed with every click you make, but my best guess from the information that you provided is that you should call
removeTarget:action:forControlEvents:
on your button between clicks.
Happy to edit my answer further if you need more detail and provide us more detail about how your code gets called
Upvotes: 1