Reputation: 685
I have a UITableView with an editButtonItem in the navigation bar. I wanted to have a tap sound play whenever the user taps the editButtonItem. Right now, I'm using the following method to play the tap sound when edit button is tapped
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
//Code to play the tap sound file
[super setEditing:editing animated:animated];}
But the problem I have is that the tap sound also plays when user swipes a tableviewcell & the delete button shows up, which is not something I want. So, my question is, is there a better way to detect when the editButtonItem is tapped?
Upvotes: 0
Views: 485
Reputation: 11855
The below code will play a sound ONLY when the edit button is tapped. When you tap Done it will not play a sound. Also, when you swipe a cell, the sound should not play.
- (void)willTransitionToState:(UITableViewCellStateMask)state
{
if (state == UITableViewCellStateShowingDeleteConfirmationMask) {
swipedToDelete = YES; // BOOL ivar
}
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
if (editing && !swipedToDelete)
{
// Play sound
}
if (swipedToDelete) {
swipedToDelete = NO;
}
}
Upvotes: 1