mirror of
https://github.com/zhigang1992/RETableViewManager.git
synced 2026-05-22 19:09:20 +08:00
Use new iOS 7 estimateHeight delegate methods, which defers most of the cost down to actual scrolling time.
This commit is contained in:
@@ -154,6 +154,11 @@
|
||||
return self.mutableSections;
|
||||
}
|
||||
|
||||
- (CGFloat)defaultTableViewHeight
|
||||
{
|
||||
return self.tableView.style == UITableViewStyleGrouped ? 44 : 22;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Table view data source
|
||||
|
||||
@@ -393,6 +398,8 @@
|
||||
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];
|
||||
if (section.headerView)
|
||||
return section.headerView.frame.size.height;
|
||||
else if (section.headerTitle.length)
|
||||
return [self defaultTableViewHeight];
|
||||
|
||||
// Forward to UITableView delegate
|
||||
//
|
||||
@@ -407,6 +414,8 @@
|
||||
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];
|
||||
if (section.footerView)
|
||||
return section.footerView.frame.size.height;
|
||||
else if (section.footerTitle.length)
|
||||
return [self defaultTableViewHeight];
|
||||
|
||||
// Forward to UITableView delegate
|
||||
//
|
||||
@@ -416,6 +425,51 @@
|
||||
return UITableViewAutomaticDimension;
|
||||
}
|
||||
|
||||
// Estimated height support
|
||||
|
||||
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
RETableViewSection *section = [self.mutableSections objectAtIndex:indexPath.section];
|
||||
id item = [section.items objectAtIndex:indexPath.row];
|
||||
|
||||
// Forward to UITableView delegate
|
||||
//
|
||||
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];
|
||||
return height ? height : UITableViewAutomaticDimension;
|
||||
}
|
||||
|
||||
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)sectionIndex {
|
||||
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];
|
||||
if (section.headerView)
|
||||
return section.headerView.frame.size.height;
|
||||
else if (section.headerTitle.length)
|
||||
return [self defaultTableViewHeight];
|
||||
|
||||
// Forward to UITableView delegate
|
||||
//
|
||||
if ([self.delegate conformsToProtocol:@protocol(UITableViewDelegate)] && [self.delegate respondsToSelector:@selector(tableView:estimatedHeightForHeaderInSection:)])
|
||||
return [self.delegate tableView:tableView estimatedHeightForHeaderInSection:sectionIndex];
|
||||
|
||||
return UITableViewAutomaticDimension;
|
||||
}
|
||||
|
||||
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)sectionIndex {
|
||||
RETableViewSection *section = [self.mutableSections objectAtIndex:sectionIndex];
|
||||
if (section.footerView)
|
||||
return section.footerView.frame.size.height;
|
||||
else if (section.footerTitle.length)
|
||||
return [self defaultTableViewHeight];
|
||||
|
||||
// Forward to UITableView delegate
|
||||
//
|
||||
if ([self.delegate conformsToProtocol:@protocol(UITableViewDelegate)] && [self.delegate respondsToSelector:@selector(tableView:estimatedHeightForFooterInSection:)])
|
||||
return [self.delegate tableView:tableView estimatedHeightForFooterInSection:sectionIndex];
|
||||
|
||||
return UITableViewAutomaticDimension;
|
||||
}
|
||||
|
||||
// Section header & footer information. Views are preferred over title should you decide to provide both
|
||||
|
||||
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)sectionIndex
|
||||
|
||||
Reference in New Issue
Block a user