问题一:预估高度执行次数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 20;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"---->:C:%d",indexPath.row);
// NSLog(@"tableview.contentInset:{%f %f %f %f}",tableView.contentInset.top,tableView.contentInset.left,tableView.contentInset.bottom,tableView.contentInset.right);
// NSLog(@"safeAreaInsets:{%f %f %f %f}",tableView.safeAreaInsets.top,tableView.safeAreaInsets.left,tableView.safeAreaInsets.bottom,tableView.safeAreaInsets.right);
// NSLog(@"adjustedContentInset:{%f %f %f %f}",tableView.adjustedContentInset.top,tableView.adjustedContentInset.left,tableView.adjustedContentInset.bottom,tableView.adjustedContentInset.right);
static NSString *reuseID = @"reuseID";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:reuseID];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];
}
//cell.backgroundColor =indexPath.row%2 ?[UIColor redColor]:[UIColor blueColor];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"---->:E:%d",indexPath.row);
if(indexPath.row == 19){
NSLog(@"----------------------");
}
return 120;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"---->:H:%d",indexPath.row);
return 120;
}
结果:
2017-11-08 14:01:48.804116+0800 测试iphoneX[80498:116614089] ---->:E:0
2017-11-08 14:01:48.804955+0800 测试iphoneX[80498:116614089] ---->:E:1
2017-11-08 14:01:48.805360+0800 测试iphoneX[80498:116614089] ---->:E:2
2017-11-08 14:01:48.805710+0800 测试iphoneX[80498:116614089] ---->:E:3
2017-11-08 14:01:48.806158+0800 测试iphoneX[80498:116614089] ---->:E:4
2017-11-08 14:01:48.806458+0800 测试iphoneX[80498:116614089] ---->:E:5
2017-11-08 14:01:48.807009+0800 测试iphoneX[80498:116614089] ---->:E:6
2017-11-08 14:01:48.807141+0800 测试iphoneX[80498:116614089] ---->:E:7
2017-11-08 14:01:48.807562+0800 测试iphoneX[80498:116614089] ---->:E:8
2017-11-08 14:01:48.807840+0800 测试iphoneX[80498:116614089] ---->:E:9
2017-11-08 14:01:48.808123+0800 测试iphoneX[80498:116614089] ---->:E:10
2017-11-08 14:01:48.808222+0800 测试iphoneX[80498:116614089] ---->:E:11
2017-11-08 14:01:48.808386+0800 测试iphoneX[80498:116614089] ---->:E:12
2017-11-08 14:01:48.808499+0800 测试iphoneX[80498:116614089] ---->:E:13
2017-11-08 14:01:48.808605+0800 测试iphoneX[80498:116614089] ---->:E:14
2017-11-08 14:01:48.808696+0800 测试iphoneX[80498:116614089] ---->:E:15
2017-11-08 14:01:48.834355+0800 测试iphoneX[80498:116614089] ---->:E:16
2017-11-08 14:01:48.835234+0800 测试iphoneX[80498:116614089] ---->:E:17
2017-11-08 14:01:48.835862+0800 测试iphoneX[80498:116614089] ---->:E:18
2017-11-08 14:01:48.836195+0800 测试iphoneX[80498:116614089] ---->:E:19
2017-11-08 14:05:22.375688+0800 测试iphoneX[80498:116614089] ----------------------
2017-11-08 14:05:22.376467+0800 测试iphoneX[80498:116614089] ---->:E:0
2017-11-08 14:05:22.376629+0800 测试iphoneX[80498:116614089] ---->:E:1
2017-11-08 14:05:22.376702+0800 测试iphoneX[80498:116614089] ---->:E:2
2017-11-08 14:05:22.376761+0800 测试iphoneX[80498:116614089] ---->:E:3
2017-11-08 14:05:22.376817+0800 测试iphoneX[80498:116614089] ---->:E:4
2017-11-08 14:05:22.376915+0800 测试iphoneX[80498:116614089] ---->:E:5
2017-11-08 14:05:22.377075+0800 测试iphoneX[80498:116614089] ---->:E:6
2017-11-08 14:05:22.377186+0800 测试iphoneX[80498:116614089] ---->:E:7
2017-11-08 14:05:22.377244+0800 测试iphoneX[80498:116614089] ---->:E:8
2017-11-08 14:05:22.377337+0800 测试iphoneX[80498:116614089] ---->:E:9
2017-11-08 14:05:22.377456+0800 测试iphoneX[80498:116614089] ---->:E:10
2017-11-08 14:05:22.378352+0800 测试iphoneX[80498:116614089] ---->:E:11
2017-11-08 14:05:22.379280+0800 测试iphoneX[80498:116614089] ---->:E:12
2017-11-08 14:05:22.379564+0800 测试iphoneX[80498:116614089] ---->:E:13
2017-11-08 14:05:22.404770+0800 测试iphoneX[80498:116614089] ---->:E:14
2017-11-08 14:05:22.405415+0800 测试iphoneX[80498:116614089] ---->:E:15
2017-11-08 14:05:22.405608+0800 测试iphoneX[80498:116614089] ---->:E:16
2017-11-08 14:05:22.405776+0800 测试iphoneX[80498:116614089] ---->:E:17
2017-11-08 14:05:22.406103+0800 测试iphoneX[80498:116614089] ---->:E:18
2017-11-08 14:05:22.406690+0800 测试iphoneX[80498:116614089] ---->:E:19
2017-11-08 14:05:27.495783+0800 测试iphoneX[80498:116614089] ----------------------
2017-11-08 14:05:27.501620+0800 测试iphoneX[80498:116614089] ---->:E:0
2017-11-08 14:05:27.501817+0800 测试iphoneX[80498:116614089] ---->:E:1
2017-11-08 14:05:27.501959+0800 测试iphoneX[80498:116614089] ---->:E:2
2017-11-08 14:05:27.502050+0800 测试iphoneX[80498:116614089] ---->:E:3
2017-11-08 14:05:27.502225+0800 测试iphoneX[80498:116614089] ---->:E:4
2017-11-08 14:05:27.502403+0800 测试iphoneX[80498:116614089] ---->:E:5
2017-11-08 14:05:27.502484+0800 测试iphoneX[80498:116614089] ---->:E:6
2017-11-08 14:05:27.502708+0800 测试iphoneX[80498:116614089] ---->:E:7
2017-11-08 14:05:27.502801+0800 测试iphoneX[80498:116614089] ---->:E:8
2017-11-08 14:05:27.502882+0800 测试iphoneX[80498:116614089] ---->:E:9
2017-11-08 14:05:27.502987+0800 测试iphoneX[80498:116614089] ---->:E:10
2017-11-08 14:05:27.503255+0800 测试iphoneX[80498:116614089] ---->:E:11
2017-11-08 14:05:27.503752+0800 测试iphoneX[80498:116614089] ---->:E:12
2017-11-08 14:05:27.504071+0800 测试iphoneX[80498:116614089] ---->:E:13
2017-11-08 14:05:27.504225+0800 测试iphoneX[80498:116614089] ---->:E:14
2017-11-08 14:05:27.504309+0800 测试iphoneX[80498:116614089] ---->:E:15
2017-11-08 14:05:27.505313+0800 测试iphoneX[80498:116614089] ---->:E:16
2017-11-08 14:05:27.505819+0800 测试iphoneX[80498:116614089] ---->:E:17
2017-11-08 14:05:27.506250+0800 测试iphoneX[80498:116614089] ---->:E:18
2017-11-08 14:05:27.506389+0800 测试iphoneX[80498:116614089] ---->:E:19
2017-11-08 14:05:34.706582+0800 测试iphoneX[80498:116614089] ----------------------
2017-11-08 14:05:34.706983+0800 测试iphoneX[80498:116614089] ---->:C:0
2017-11-08 14:05:34.708590+0800 测试iphoneX[80498:116614089] ---->:H:0
2017-11-08 14:05:34.733020+0800 测试iphoneX[80498:116614089] ---->:C:1
2017-11-08 14:05:34.734087+0800 测试iphoneX[80498:116614089] ---->:H:1
2017-11-08 14:05:34.734730+0800 测试iphoneX[80498:116614089] ---->:C:2
2017-11-08 14:05:34.735399+0800 测试iphoneX[80498:116614089] ---->:H:2
2017-11-08 14:05:34.735917+0800 测试iphoneX[80498:116614089] ---->:C:3
2017-11-08 14:05:34.736581+0800 测试iphoneX[80498:116614089] ---->:H:3
2017-11-08 14:05:34.737039+0800 测试iphoneX[80498:116614089] ---->:C:4
2017-11-08 14:05:34.737717+0800 测试iphoneX[80498:116614089] ---->:H:4
2017-11-08 14:05:34.739139+0800 测试iphoneX[80498:116614089] ---->:C:5
2017-11-08 14:05:34.739782+0800 测试iphoneX[80498:116614089] ---->:H:5
2017-11-08 14:05:34.740299+0800 测试iphoneX[80498:116614089] ---->:C:6
2017-11-08 14:05:34.740913+0800 测试iphoneX[80498:116614089] ---->:H:6
2017-11-08 14:05:34.742304+0800 测试iphoneX[80498:116614089] ---->:H:0
2017-11-08 14:05:34.742504+0800 测试iphoneX[80498:116614089] ---->:H:1
2017-11-08 14:05:34.742626+0800 测试iphoneX[80498:116614089] ---->:H:2
2017-11-08 14:05:34.742726+0800 测试iphoneX[80498:116614089] ---->:H:3
2017-11-08 14:05:34.748167+0800 测试iphoneX[80498:116614089] ---->:H:4
2017-11-08 14:05:34.748854+0800 测试iphoneX[80498:116614089] ---->:H:5
2017-11-08 14:05:34.750600+0800 测试iphoneX[80498:116614089] ---->:H:6
说明:iOS11 在刷新cell的时候先执行三遍 estimatedHeightForRowAtIndexPath预估高度, 然后才执行 cellForRowAtIndexPath heightForRowAtIndexPath交替个一边
iOS 11 tableView刷新cell个数问题
iOS 11 在tableView首屏刷新的时候刷新个数 = 2 * (屏幕高度/cell高度+1)
例如:屏幕高度667 cell 高度 100 则为 2*(667 /100)