#import <UIKit/UIKit.h> @interface OperationActionSheet : UIActionSheet <UIActionSheetDelegate> { } @property (copy) void (^pauseOrResumeBlock)(); @property (copy) void (^removeBlock)(); - (id)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitle:(NSString *)otherButtonTitle pauseOrResumeAction:(void (^)())pauseOrResumeBlock removeAction:(void (^)())removeBlock; @end
#import "OperationActionSheet.h" @implementation OperationActionSheet @synthesize pauseOrResumeBlock = _pauseOrResumeBlock, removeBlock = _removeBlock; - (id)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitle:(NSString *)otherButtonTitle pauseOrResumeAction:(void (^)())pauseOrResumeBlock removeAction:(void (^)())removeBlock { self = [super initWithTitle:title delegate:self cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle otherButtonTitles: otherButtonTitle, nil]; if (self) { _pauseOrResumeBlock = Block_copy(pauseOrResumeBlock); _removeBlock = Block_copy(removeBlock); } return self; } -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { NSAssert(actionSheet == self, @"Wrong Action Sheet passed"); NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex]; if ([title isEqualToString:@"Pause"]) { if (self.pauseOrResumeBlock) { self.pauseOrResumeBlock(); } } else if ([title isEqualToString:@"Remove"]) { if (self.removeBlock) { self.removeBlock(); } } } @end
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { OperationActionSheet *asOperation = [[OperationActionSheet alloc] initWithTitle: @"title" cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Pause" otherButtonTitle:@"Remove" pauseOrResumeAction:^{ NSLog(@"pauseOrResumeAction....."); //do something here... //重新加载变更的表格 [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } removeAction:^{ //do something.... //删除单元格 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; }]; [asOperation showFromToolbar:self.navigationController.toolbar]; [asOperation release]; }