0
所以在我的集合视图单元格中我有文本和图像:这是我在CollectionViewLayout中的代码。为什么我的Collectionview cell.image不见了,搞砸了?
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if let content = HomeCollectionViewController.posts[indexPath.item].content {
let spaceForPostContentLabel = NSString(string: content).boundingRect(with: CGSize(width: view.frame.width - 32, height: 120), options: NSStringDrawingOptions.usesFontLeading.union(NSStringDrawingOptions.usesLineFragmentOrigin), attributes: [NSFontAttributeName: UIFont.systemFont(ofSize: 15)], context: nil)
if HomeCollectionViewController.posts[indexPath.item].imageURL != nil {
return CGSize(width: view.frame.width, height: spaceForPostContentLabel.height + postImageViewOriginHeight + 168.0)
} else {
return CGSize(width: view.frame.width, height: spaceForPostContentLabel.height + 152.5)
}
} else {
return CGSize(width: view.frame.width, height: 408.5)
}
}
一切都很好,当它第一次加载。但是当我向下滚动并再次滚动时,一切都变得混乱起来,图像消失了,图像应该已经存在一个巨大的空白空间。这是否与dequeReusableIdentifier有关?
注:此错误仅发生在第一个单元,其他单元有图像由于如何出队工作正常工作
你确定吗?这仍然不适用于我 –