首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >嵌套UITableVIew heightForRowAtIndexPath

嵌套UITableVIew heightForRowAtIndexPath
EN

Stack Overflow用户
提问于 2014-02-24 14:53:22
回答 2查看 464关注 0票数 0

我试图找出如何优化性能和提高代码质量。我有以下布局:

代码语言:javascript
复制
OuterTableView
 Outer Cell
  UILabel (title label)
  InnerTableView
   Inner Cell (item cell)
   Inner Cell (item cell)
   ...

此布局的用途是可扩展的外表。在折叠状态下,只有UILabel (只有标题标签)是可见的。当用户单击外部单元格时,单元格被展开并显示内部单元格。

外表控制器中,有3个函数(简化):

代码语言:javascript
复制
- (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;
}

内表控制器

代码语言:javascript
复制
- (void)layoutSubviews {
    [self.cellTableView layoutSubviews];
    // set height constraint for inner table view
    self.heightLayoutConstraint.constant = self.cellTableView.contentSize.height;
}

我有以下问题: 1)如您所见,外层表的每个单元格都会调用configureCell两次。有任何方法来缓存或只调用一次吗? 2) systemLayoutSizeFittingSize返回0。有什么好主意吗?

EN

回答 2

Stack Overflow用户

发布于 2014-06-12 02:07:48

2) systemLayoutSizeFittingSize返回0。有什么好主意吗?

你的约束可能已经消失了。确保为.xib文件中单元格的宽度和高度指定约束。

票数 0
EN

Stack Overflow用户

发布于 2014-02-24 14:59:20

我认为其他细胞内部的细胞是个坏主意。您可以创建一些节,并且在用户点击区段中的单元格时,可以使用didSelectRowAtIndexPath方法将单元格添加到本节。或者将滚动视图与自定义nsview一起使用,其中放置表视图。那只是周旋而已。

有任何方法来缓存或只调用一次吗?-尝试willDisplayCell方法。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21991173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档