我有一个带有部分的 tableView,可以打开和关闭。所以,当我点击一个部分打开它时,它被单元格填满,并且 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
被调用我在 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
中提供的次数。
这样对吗?不应该只是可见细胞的数量吗?
因为我的情况很糟糕:我有很多自定义单元格(50~100 个单元格)并调用 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
每个单元格都会减慢部分的打开速度,因为每次从 nib 执行读取并且单元格内容都被图像填充。
我检查了 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
中单元格的可见性,如下所示:
if ([[self.tableView indexPathsForVisibleRows] containsObject:indexPath])
NSLog(@"visible %@", indexPath);
它显示在 45 个单元格中,只有 6 或 7 个是可见的。其他人不在可见区域。但是创建单元格仍然执行。 这是代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"IVCell";
IVCamera *camera = [server.cameras objectAtIndex:indexPath.row];
IVServerListViewCell *cell = (IVServerListViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"IVServerListCell" owner:self options:nil];
cell = (IVServerListViewCell*)_tableViewCell;
self.tableViewCell = nil;
}
[cell textLabel].text = camera.cameraName;
cell.preview = camera.preview;
cell.userData = camera;
cell.isEnabled = (server.isInactive)?NO:camera.isOnline;
return cell;
}
它仍然正确吗?还是我遗漏了什么?
最佳答案
增加你的
estimatedRowHeight of UITableview.
关于ios - TableView : cellForRowAtIndexPath: get called not only for visible cells?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9286025/