我有UITableView,其中的单元格包含具有不同高度的水平UICollectionView。当我滚动以便可以看到2个收藏夹视图时,我快速向下滚动至该视图时,它已损坏。它的高度不好,现在不再是水平的,该集合现在是垂直的+我可以看到“弹跳效果”。你知道如何解决这个问题吗?
var viewModel: TitleAccessoryButtonCollectionViewModel? {
didSet {
guard let viewModel = viewModel else {
return
}
titleLabel.text = viewModel.title
if let buttonTitle = viewModel.accessoryButtonModel?.title {
setAccessoryButtonTitle(buttonTitle)
}else{
accessoryButton.hideTitleLabel()
}
if let buttonImage = viewModel.accessoryButtonModel?.image {
accessoryButton.buttonImageView.image = buttonImage
}
else {
accessoryButton.hideImageView()
}
sectionContentImage.image = viewModel.sectionContentImage
titleLabelLeadingConstraint.constant = viewModel.titleLabelLeadingSpacing
accessoryButton.isHidden = viewModel.hideAccessoryButton
sectionContentView.isHidden = viewModel.hidePremiumContentView
let collectionViewModel = viewModel.collectionViewModel
collectionViewHeight.constant = CGFloat(collectionViewModel.height)
print(collectionViewHeight.constant)
print(collectionView.bounds.height)
collectionViewModel.setup(collectionView: collectionView)
collectionView.delegate = collectionViewModel.delegate
collectionView.dataSource = collectionViewModel.dataSource
collectionView.reloadData()
collectionView.layoutIfNeeded()
}
}
viewModel被添加到:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
registerCells()
guard let cell = tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifierForItem(at: indexPath.row), for: indexPath) as? HorizontalCollectionTableViewCell else {
return UITableViewCell()
}
if cellViewModels.count > indexPath.row {
let viewModel = cellViewModels[indexPath.row]
cell.viewModel = viewModel
}
return cell
}