英语水平有限,不逐一翻译了,表达的是:
当UITableView在初始化和reloadData时会首先调用cell个数次- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath,因为UITableView需要知道总高度后才能继续描画出内容。
之后会挨次调用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath和
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
如果是固定高度的Cell的这样就可以了。
但是我们经常会遇到变化的高度,这时我们用
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
}
此时,当UITableView再初始化和reloadData时不会调用heightForRowAtIndexPath了,而是调用estimatedHeightForRowAtIndexPath,estimatedHeightForRowAtIndexPath是一个估计值,之后会在挨次调用cellForRowAtIndexPath和heightForRowAtIndexPath时逐一更改。
原版在GitHub上有demo,我自己也写了个测试的,需要的留邮箱吧。