【问题标题】:iOS TableView inside of a CollectionView sometimes shows incorrect dataCollectionView 内的 iOS TableView 有时会显示不正确的数据
【发布时间】:2018-06-12 03:05:24
【问题描述】:

我有一个collectionView,我在tableView 中显示了一个cmets 列表。我看到滚动 collectionView 时 tableView 数据不正确。

我尝试使用 prepareForReuse() 来解决这个问题,但它不起作用。这是我的代码:

override func prepareForReuse() {
        super.prepareForReuse()
        imageView.image = UIImage()
        commentsTableView = UITableView()
    }

如果有人可以为此提出解决方案,我将不胜感激。

谢谢。

【问题讨论】:

  • 向我们展示您的 CollectionView 和 TableView 代码

标签: ios swift uitableview uicollectionview


【解决方案1】:

将所有属性赋值为 nil。

override func prepareForReuse() {

        imageView.image = nil
        commentsTableView = nil
        super.prepareForReuse()
    }

但请确保您的属性是可选的。

【讨论】:

  • 感谢您的回答,我会尝试一下并告诉您是否有效。 super.prepareForReuse() 到底有什么原因吗?一般在被覆盖的视图函数中,我们在函数的开头调用超类方法。
  • 我试过了,但不幸的是没有解决它。有时仍然会看到错误的数据,当表格重新加载时(滚动时)会得到纠正
  • 哦,你能在表格单元格中检查约束你的项目吗?让一切都正确。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-13
  • 1970-01-01
相关资源
最近更新 更多