When deleting a row in a table view, I want to show an action sheet that needs confirmation in certain situations. When the answer sheet says “Yes” (destructive action), I delete the row of the table, and everything is in order. But when the Cancel button is pressed, I still see the Delete button in the pressed state.
What I do in tableView:commitEditingStyle when deleting:
BlockBasedActionSheet *askSheet = [[BlockBasedActionSheet alloc] initWithTitle:@"Delete entry?" cancelButtonTitle:@"No" destructiveButtonTitle:@"Yes, delete child also records" cancelAction:^{ UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath]; if (cell.showingDeleteConfirmation) { cell.editing = NO; cell.editingAccessoryView = nil; cell.editing = YES; } } destructiveAction:deleteBlock]; [askSheet showInView:self.view]; [askSheet release];
It is also strange that the showingDeleteConfirmation cell showingDeleteConfirmation is NO , although the Delete button is still visible.
I use a home-made implementation of a block-based action block. There may be a mistake, although I seem to be getting the correct cell in the undo block.
So, how can I reset the “Delete” button to “not pressed” and delete it, and then return the round delete button to a horizontal position, how does it happen when I click somewhere on the screen?
BlockBasedActionSheet.h helper BlockBasedActionSheet.h :
@interface BlockBasedActionSheet : UIActionSheet<UIActionSheetDelegate> { } @property (copy) void (^cancelBlock)(); @property (copy) void (^destructiveBlock)(); - (id)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle cancelAction:(void (^)())cancelBlock destructiveAction:(void (^)())destructiveBlock; @end
BlockBasedActionSheet.m implementation BlockBasedActionSheet.m :
#import "BlockBasedActionSheet.h" @implementation BlockBasedActionSheet @synthesize cancelBlock = _cancelBlock, destructiveBlock = _destructiveBlock; - (id)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle cancelAction:(void (^)())cancelBlock destructiveAction:(void (^)())destructiveBlock { self = [super initWithTitle:title delegate:self cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle otherButtonTitles: nil]; if (self) { _cancelBlock = Block_copy(cancelBlock); _destructiveBlock = Block_copy(destructiveBlock); } return self; } -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { NSAssert(actionSheet == self, @"Wrong Action Sheet passed"); if (buttonIndex == [self cancelButtonIndex]) { if (self.cancelBlock) { self.cancelBlock(); } } else { if (self.destructiveBlock) { self.destructiveBlock(); } } } @end
ios iphone uitableview
Björn landmesser
source share