From 5d3bd3bad090336dbf3ca6064e6bde3830f2e2e0 Mon Sep 17 00:00:00 2001 From: Austin Drummond Date: Thu, 13 Aug 2015 13:10:46 -0400 Subject: [PATCH 1/2] fixed invalid next responder check if not found A bug exists when indexPathForNextResponderInSectionIndex: on RETableViewCell.m if the sections do not match. If not, the value is set to -1. The for loop below automaticall adds 1 to the unsigned -1, which makes it 0. Thus, the for loop condition was met when it shouldn't have been. By setting it to -2 then subtracting the number of items in the section, the for loop conidition will never be met when the section is not equal. --- RETableViewManager/RETableViewCell.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RETableViewManager/RETableViewCell.m b/RETableViewManager/RETableViewCell.m index d76c554..9d9f8bf 100755 --- a/RETableViewManager/RETableViewCell.m +++ b/RETableViewManager/RETableViewCell.m @@ -250,7 +250,7 @@ - (NSIndexPath *)indexPathForPreviousResponder - (NSIndexPath *)indexPathForNextResponderInSectionIndex:(NSUInteger)sectionIndex { RETableViewSection *section = [self.tableViewManager.sections objectAtIndex:sectionIndex]; - NSUInteger indexInSection = [section isEqual:self.section] ? [section.items indexOfObject:self.item] : -1; + NSUInteger indexInSection = [section isEqual:self.section] ? [section.items indexOfObject:self.item] : -2 - section.items.count; for (NSInteger i = indexInSection + 1; i < section.items.count; i++) { RETableViewItem *item = [section.items objectAtIndex:i]; if ([item isKindOfClass:[RETableViewItem class]]) { From 4ae69593435c6680c6fd21ecf9a9ddf9a8f1542c Mon Sep 17 00:00:00 2001 From: Austin Drummond Date: Tue, 18 Aug 2015 09:44:06 -0400 Subject: [PATCH 2/2] added editing accessory view --- RETableViewManager/RETableViewCell.m | 2 ++ RETableViewManager/RETableViewItem.h | 3 +++ RETableViewManager/RETableViewManager.m | 19 +++++++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/RETableViewManager/RETableViewCell.m b/RETableViewManager/RETableViewCell.m index 9d9f8bf..aba43cb 100755 --- a/RETableViewManager/RETableViewCell.m +++ b/RETableViewManager/RETableViewCell.m @@ -106,6 +106,8 @@ - (void)cellWillAppear self.textLabel.backgroundColor = [UIColor clearColor]; self.accessoryType = item.accessoryType; self.accessoryView = item.accessoryView; + self.editingAccessoryType = item.editingAccessoryType; + self.editingAccessoryView = item.editingAccessoryView; self.textLabel.textAlignment = item.textAlignment; if (self.selectionStyle != UITableViewCellSelectionStyleNone) self.selectionStyle = item.selectionStyle; diff --git a/RETableViewManager/RETableViewItem.h b/RETableViewManager/RETableViewItem.h index e460ff0..0434cfb 100644 --- a/RETableViewManager/RETableViewItem.h +++ b/RETableViewManager/RETableViewItem.h @@ -40,11 +40,14 @@ @property (assign, readwrite, nonatomic) UITableViewCellStyle style; @property (assign, readwrite, nonatomic) UITableViewCellSelectionStyle selectionStyle; @property (assign, readwrite, nonatomic) UITableViewCellAccessoryType accessoryType; +@property (assign, readwrite, nonatomic) UITableViewCellAccessoryType editingAccessoryType; @property (assign, readwrite, nonatomic) UITableViewCellEditingStyle editingStyle; @property (strong, readwrite, nonatomic) UIView *accessoryView; +@property (strong, readwrite, nonatomic) UIView *editingAccessoryView; @property (assign, readwrite, nonatomic) BOOL enabled; @property (copy, readwrite, nonatomic) void (^selectionHandler)(id item); @property (copy, readwrite, nonatomic) void (^accessoryButtonTapHandler)(id item); +@property (copy, readwrite, nonatomic) void (^editingAccessoryButtonTapHandler)(id item); @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)); diff --git a/RETableViewManager/RETableViewManager.m b/RETableViewManager/RETableViewManager.m index fb380d2..ecf2be1 100755 --- a/RETableViewManager/RETableViewManager.m +++ b/RETableViewManager/RETableViewManager.m @@ -563,10 +563,21 @@ - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexP { RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section]; id item = [section.items objectAtIndex:indexPath.row]; - if ([item respondsToSelector:@selector(setAccessoryButtonTapHandler:)]) { - RETableViewItem *actionItem = (RETableViewItem *)item; - if (actionItem.accessoryButtonTapHandler) - actionItem.accessoryButtonTapHandler(item); + + if (self.tableView.editing) { + + if ([item respondsToSelector:@selector(setEditingAccessoryButtonTapHandler:)]) { + RETableViewItem *actionItem = (RETableViewItem *)item; + if (actionItem.editingAccessoryButtonTapHandler) + actionItem.editingAccessoryButtonTapHandler(item); + } + + } else { + if ([item respondsToSelector:@selector(setAccessoryButtonTapHandler:)]) { + RETableViewItem *actionItem = (RETableViewItem *)item; + if (actionItem.accessoryButtonTapHandler) + actionItem.accessoryButtonTapHandler(item); + } } // Forward to UITableView delegate