我有一个带有部分的 tableView,可以打开和关闭。因此,当我点击一个部分将其打开时,它会被单元格填满并且-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
被呼叫的次数与我提供的次数完全相同-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
.
那是对的吗?它不应该只是可见细胞的数量吗?
因为就我而言,我的情况很糟糕:我有很多自定义单元格(50~100 个单元格)并调用-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
对于每个单元格都会减慢部分的打开速度,因为每次执行从笔尖读取并且单元格内容都被图像填充。
我检查了单元格内部的可见性-(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;
}
仍然正确吗?或者我错过了什么?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)