为了提高性能,UITableView在iOS7后引入了估算高度,源码是这样解释的:
// Use the estimatedHeight methods to quickly calcuate guessed values which will allow for fast load times of the table.
// If these methods are implemented, the above -tableView:heightForXXX calls will be deferred until views are ready to be displayed, so more expensive logic can be placed there.
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(7_0);
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)sectionNS_AVAILABLE_IOS(7_0);
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)sectionNS_AVAILABLE_IOS(7_0);
没有实现estimatedHeightForRowAtIndexPath方法时,调用顺序如下:
1、numberOfRowsInSection
2、heightForRowAtIndexPath
3、cellForRowAtIndexPath
如果实现了estimatedHeightForRowAtIndexPath方法,调用顺序如下:
1、numberOfRowsInSection(不变)
2、estimatedHeightForRowAtIndexPath
3、cellForRowAtIndexPath
4、heightForRowAtIndexPath