【发布时间】:2019-07-04 22:36:47
【问题描述】:
我有一个 collectionView,我在其中显示带有 UIButton 的普通 UICollectionViewCell。在另一个屏幕上,我有一个开关列表。每当这些更改时,就会使用 collectionView 将更新发送到屏幕。当我关闭开关(并且数据源已更新)时,我尝试使用 reloadData 函数重新填充 collectionView。但是,按钮(单元格)显示在彼此的顶部。
我尝试使用 reloadData,在 Dispatch.main.async 中执行此操作,使 collectionView 无效,删除 deleteSections 函数并访问特定单元格并使用 cell.removeFromSuperView() 将其删除。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "identifier", for: indexPath)
let name = PickingState.getSelectedFilterValues()[indexPath.row]
let button = SelectionsItem(title: name, frame: createMockupButtonToGetFrame(name: name))
print(name)
cell.contentView.addSubview(button)
cell.contentView.addConstraintsWithFormat(formatString: "H:|[v0]|", views: button)
cell.contentView.addConstraintsWithFormat(formatString: "V:|[v0]|", views: button)
return cell
}
期望单元格重新渲染,而不是彼此重叠。
【问题讨论】:
标签: swift uicollectionview reloaddata