【问题标题】:UITableView contentSize does not updatedUITableView contentSize 没有更新
【发布时间】:2018-10-05 14:27:42
【问题描述】:

我有 UITableView 和 UITableViewCell,其中包含 UICollectionView,如:

  • UITableViewCell
  • UITableViewCell
    • UICollectionViewCell
    • UICollectionViewCell

在 UICollectionView 中数据是动态添加的。 我已经订阅了 UICollectionView contentSize,并且我正在根据 contentSize 更改 UICollectionView 的框架。它工作正常,包含 UICollectionView 的 UITableViewCell 框架正在正确更改,但 UITableView contentSize 没有更新。我不明白为什么?

UITableView 项目高度设置为 UITableViewAutomaticDimension

【问题讨论】:

  • 请提供一些代码作为示例:-)
  • 我什至不知道提供给什么.. ``` collectionView.rx.contentSize .subscribe(onNext: { [collectionView] contentSize in guard let collectionView = collectionView else { return } collectionView.frame = CGRect(origin: collectionView.frame.origin, size: contentSize) }).disposed(by: bag) ``
  • 我已经订阅了 UICollectionView contentSize,我正在根据 contentSize 更改 UICollectionView 的框架这样做的原因是什么?
  • @arturdev 为了让 UITableView 自动重新计算自己的 contentSize,以及当我们拥有带有单个 UILabel(顶部、底部、前导、尾随约束)的 UITableViewCell 以及 UILabel 扩展时,UITableViewCell 和 contentSize 相应地扩展
  • @Gikas 能否提供所需结果的屏幕截图?

标签: ios swift uitableview uicollectionview


【解决方案1】:

我找到的最佳解决方案。这是手动计算高度,不使用 UITableViewAutomaticDimension。

是的,你必须花时间来写这篇文章。

在 UICollectionViewCell 的每个添加元素之后,您需要更新您的 tableView(取决于适合您的):

【讨论】:

    猜你喜欢
    • 2015-05-04
    • 2015-08-08
    • 2013-03-04
    • 2014-10-19
    • 2012-04-15
    • 2014-02-11
    • 1970-01-01
    • 2012-03-28
    • 1970-01-01
    相关资源
    最近更新 更多