Ability to set deletionHanlder without completion

This commit is contained in:
Roman Efimov
2013-04-30 12:35:54 -05:00
parent e590e2c507
commit 2fd2f7593f
3 changed files with 4 additions and 2 deletions

View File

@@ -43,6 +43,7 @@
@property (copy, readwrite, nonatomic) void (^accessoryButtonTapHandler)(id item);
@property (assign, readwrite, nonatomic) BOOL movable;
@property (copy, readwrite, nonatomic) void (^insertionHandler)(id item);
@property (copy, readwrite, nonatomic) void (^deletionHandler)(id item);
@property (copy, readwrite, nonatomic) void (^deletionHandlerWithCompletion)(id item, void (^)(void));
@property (copy, readwrite, nonatomic) void (^moveHandler)(id item, NSIndexPath *sourceIndexPath, NSIndexPath *destinationIndexPath);
@property (copy, readwrite, nonatomic) BOOL (^allowNewIndexPath)(NSIndexPath *newIndexPath);

View File

@@ -241,6 +241,8 @@
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
});
} else {
if (item.deletionHandler)
item.deletionHandler(item);
[section.items removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}

View File

@@ -40,9 +40,8 @@
for (NSInteger i = 1; i <= 5; i++) {
RETableViewItem *item = [RETableViewItem itemWithTitle:[NSString stringWithFormat:@"Section 1, Item %i", i] accessoryType:UITableViewCellAccessoryNone selectionHandler:nil];
item.editingStyle = UITableViewCellEditingStyleDelete;
item.deletionHandlerWithCompletion = ^(RETableViewItem *item, void (^completion)(void)) {
item.deletionHandler = ^(RETableViewItem *item) {
NSLog(@"Item removed: %@", item.title);
completion();
};
[section addItem:item];
}