Skip to content

Commit

Permalink
Revert "Revert "Safeguards""
Browse files Browse the repository at this point in the history
  • Loading branch information
romaonthego committed Feb 28, 2015
1 parent 13844fd commit df53394
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions RETableViewManager/RETableViewManager.m
Expand Up @@ -169,6 +169,9 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
{
if (self.mutableSections.count <= sectionIndex) {
return 0;
}
return ((RETableViewSection *)[self.mutableSections objectAtIndex:sectionIndex]).items.count;
}

Expand Down Expand Up @@ -258,12 +261,18 @@ - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

- (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;
}
Expand All @@ -283,6 +292,9 @@ - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sou

- (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;
Expand Down Expand Up @@ -414,6 +426,9 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)sectionIndex
{
if (self.mutableSections.count <= sectionIndex) {
return UITableViewAutomaticDimension;
}
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];

if (section.headerHeight != RETableViewSectionHeaderHeightAutomatic) {
Expand Down Expand Up @@ -463,6 +478,9 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)sectionIndex
{
if (self.mutableSections.count <= sectionIndex) {
return UITableViewAutomaticDimension;
}
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];

if (section.footerHeight != RETableViewSectionFooterHeightAutomatic) {
Expand Down Expand Up @@ -514,16 +532,17 @@ - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSIntege

- (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];

Expand All @@ -534,6 +553,9 @@ - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)sectionIndex
{
if (self.mutableSections.count <= sectionIndex) {
return nil;
}
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];

// Forward to UITableView delegate
Expand All @@ -546,6 +568,9 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)sectionIndex
{
if (self.mutableSections.count <= sectionIndex) {
return nil;
}
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];

// Forward to UITableView delegate
Expand Down

0 comments on commit df53394

Please sign in to comment.