ios - TableView : cellForRowAtIndexPath: get called not only for visible cells?

标签 ios uitableview

我有一个带有部分的 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/

相关文章:

ios - UITableView 页脚,停止在内容上 float

ios - 应用程序崩溃然后重新加载 tableview 数据

ios - UIPickerView 方法将 UIPickerView 对象作为参数但未使用

ios - (quickblox) 如何将人员添加到聊天对话框?

ios - Swift 2.0 UITableView 部分标题在点击时滚动到顶部

ios - 了解 NSNetservice 的 “includesPeerToPeer” 属性

ios - 基于Segment-Control将数组加载到TableView

android - 元素类型 'List<widget>' 不能分配给列表类型 'Widget'

ios - 从 UIPickerView 截取的图片

swift - TableView 的加载和平滑度