我试图找出如何优化性能和提高代码质量。我有以下布局:
OuterTableView
Outer Cell
UILabel (title label)
InnerTableView
Inner Cell (item cell)
Inner Cell (item cell)
...此布局的用途是可扩展的外表。在折叠状态下,只有UILabel (只有标题标签)是可见的。当用户单击外部单元格时,单元格被展开并显示内部单元格。
在外表控制器中,有3个函数(简化):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.tableView) {
// ServiceGroupCell - outer cell
ServiceGroupCell *serviceCell = [tableView dequeueReusableCellWithIdentifier:@"service_group_cell"];
[self configureCell:serviceCell forIndexPath:indexPath];
return serviceCell;
}
return nil;
}
- (void) configureCell:(ServiceGroupCell *) cell forIndexPath:(NSIndexPath *) indexPath {
// styling for outer cell and passing data for inner cells
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
ServiceGroupCell *serviceGroupCell = [tableView dequeueReusableCellWithIdentifier:@"service_group_cell"];
[self configureCell:serviceGroupCell forIndexPath:indexPath];
[serviceGroupCell layoutSubviews];
CGFloat height = [serviceGroupCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return height;
}内表控制器
- (void)layoutSubviews {
[self.cellTableView layoutSubviews];
// set height constraint for inner table view
self.heightLayoutConstraint.constant = self.cellTableView.contentSize.height;
}我有以下问题: 1)如您所见,外层表的每个单元格都会调用configureCell两次。有任何方法来缓存或只调用一次吗? 2) systemLayoutSizeFittingSize返回0。有什么好主意吗?
发布于 2014-06-12 02:07:48
2) systemLayoutSizeFittingSize返回0。有什么好主意吗?
你的约束可能已经消失了。确保为.xib文件中单元格的宽度和高度指定约束。
发布于 2014-02-24 14:59:20
我认为其他细胞内部的细胞是个坏主意。您可以创建一些节,并且在用户点击区段中的单元格时,可以使用didSelectRowAtIndexPath方法将单元格添加到本节。或者将滚动视图与自定义nsview一起使用,其中放置表视图。那只是周旋而已。
有任何方法来缓存或只调用一次吗?-尝试willDisplayCell方法。
https://stackoverflow.com/questions/21991173
复制相似问题