From df53394eeec024f89fb1cbb9f60913544dcd134b Mon Sep 17 00:00:00 2001 From: Roman Efimov Date: Fri, 27 Feb 2015 16:58:02 -0800 Subject: [PATCH] Revert "Revert "Safeguards"" --- RETableViewManager/RETableViewManager.m | 33 ++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/RETableViewManager/RETableViewManager.m b/RETableViewManager/RETableViewManager.m index 46f82d3..a90d9d8 100755 --- a/RETableViewManager/RETableViewManager.m +++ b/RETableViewManager/RETableViewManager.m @@ -169,6 +169,9 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex { + if (self.mutableSections.count <= sectionIndex) { + return 0; + } return ((RETableViewSection *)[self.mutableSections objectAtIndex:sectionIndex]).items.count; } @@ -258,12 +261,18 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)sectionIndex { + if (self.mutableSections.count <= sectionIndex) { + return nil; + } RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex]; return section.headerTitle; } - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)sectionIndex { + if (self.mutableSections.count <= sectionIndex) { + return nil; + } RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex]; return section.footerTitle; } @@ -283,6 +292,9 @@ - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { + if (self.mutableSections.count <= indexPath.section) { + return NO; + } RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section]; RETableViewItem *item = [section.items objectAtIndex:indexPath.row]; return item.moveHandler != nil; @@ -414,6 +426,9 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)sectionIndex { + if (self.mutableSections.count <= sectionIndex) { + return UITableViewAutomaticDimension; + } RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex]; if (section.headerHeight != RETableViewSectionHeaderHeightAutomatic) { @@ -463,6 +478,9 @@ - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)sectionIndex { + if (self.mutableSections.count <= sectionIndex) { + return UITableViewAutomaticDimension; + } RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex]; if (section.footerHeight != RETableViewSectionFooterHeightAutomatic) { @@ -514,16 +532,17 @@ - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { + if (self.mutableSections.count <= indexPath.section) { + return UITableViewAutomaticDimension; + } RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section]; id item = [section.items objectAtIndex:indexPath.row]; // Forward to UITableView delegate // - IF_IOS7_OR_GREATER ( - if ([self.delegate conformsToProtocol:@protocol(UITableViewDelegate)] && [self.delegate respondsToSelector:@selector(tableView:estimatedHeightForRowAtIndexPath:)]) - return [self.delegate tableView:tableView estimatedHeightForRowAtIndexPath:indexPath]; - ); + if ([self.delegate conformsToProtocol:@protocol(UITableViewDelegate)] && [self.delegate respondsToSelector:@selector(tableView:estimatedHeightForRowAtIndexPath:)]) + return [self.delegate tableView:tableView estimatedHeightForRowAtIndexPath:indexPath]; CGFloat height = [[self classForCellAtIndexPath:indexPath] heightWithItem:item tableViewManager:self]; @@ -534,6 +553,9 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)sectionIndex { + if (self.mutableSections.count <= sectionIndex) { + return nil; + } RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex]; // Forward to UITableView delegate @@ -546,6 +568,9 @@ - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)sectionIndex { + if (self.mutableSections.count <= sectionIndex) { + return nil; + } RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex]; // Forward to UITableView delegate