【发布时间】:2018-10-17 21:27:27
【问题描述】:
我创建了一个包含collectionView 的custom UITableViewCell。此自定义单元格符合 UICollectionViewDelegate 和 UICollectionViewDataSource 协议,并管理 collectionView。
但是当我在 tableView 中使用这个自定义单元格时,即使屏幕上只有 3 个单元格可见,我的 collectionView 的 visibleCells 属性也会返回所有 20 个单元格。
这会导致我的 collectionView 不重用单元格,因为它认为所有单元格在屏幕上都是可见的并导致内存问题。
这是我在 tableViewController 中的实现:
override func viewDidLoad() {
super.viewDidLoad()
guard let bundle = Bundle(identifier: "org.cocoapods.*****") else { return }
tableView.register(UINib(nibName: "CampaignCollectionViewContainerCell", bundle: bundle), forCellReuseIdentifier: "campaignContainerCellIdentifier")
}
.
.
.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "campaignContainerCellIdentifier") as? CampaignCollectionViewContainerCell else { fatalError() }
return cell
}
我尝试更改 visibleCells 属性,但它是 get-only。
我想没关系,但我的自定义 UITableViewCell 位于私有 pod 中,而 UITableViewController 位于使用此 pod 的主项目中。
【问题讨论】:
标签: ios swift uitableview uicollectionview