[英]UITableView with limited number of cells
我有一个UITableView
±10不同UITableViewCells
以显示有关的对象(描述细胞,细胞的照片等)的全部信息。 因此,在加载UITableView
时,不需要UITableView
单元格可以重用。 如果我以某种方式存储UITableViewCells
并阻止调用cellForRowAtIndexPath
,性能是否会更好? 如果是这样,实现相同行为的方法是什么?
首先,如果您要使用UITableView,则不能阻止cellForRowAtIndexPath被调用。 它是一个UITableViewDataSource函数,不是可选的。 否则,您将无法填充表视图。
您可以做的是在cellForRowAtIndexPath中的indexpath.row上使用case切换,并返回必要的单元格。
您可以通过在Storyboard中增加原型单元来尝试。 每个单元格都分配了新的单元格标识符,您需要使标识符数组与故事板的索引保持匹配。
您的cellForRowAtIndexpath将减少为:
- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:[cellIdArray objectAtIndex:indexPath.row] forIndexPath:indexPath];
return cell;
}
注意:cellForRowAtIndexpath方法将始终被调用。 在上述情况下,您可以将数据放在情节提要中。 在https://www.appcoda.com/sidebar-menu-swift/查看类似情况
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.