Я пытаюсь установить размер для своей ячейки в соответствии с тем, что внутри, это мой код, и он падает, и я не могу найти сообщение об ошибке.
extension TimelineCollectionVC: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "timeline", for: indexPath) as? Timeline
cell?.textView.translatesAutoresizingMaskIntoConstraints = true
cell?.textView.sizeToFit()
if cell?.containerView.subviews.count == 0 {
cell?.containerHeight.constant = 1
} else {
cell?.containerHeight.constant = (cell?.containerView.subviews.first?.frame.size.height) ?? 80
}
let cellHeight = (cell?.upperView.bounds.height)! + (cell?.textView.bounds.height)! + (cell?.containerView.bounds.height)! + (cell?.lowerView.bounds.height)!
return CGSize(width: 375, height: cellHeight)
}
}
Вы не должны использовать
extension TimelineCollectionVC: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "timeline", for: indexPath) as? Timeline
cell?.textView.translatesAutoresizingMaskIntoConstraints = true
cell?.textView.sizeToFit()
if cell?.containerView.subviews.count == 0 {
cell?.containerHeight.constant = 1
} else {
cell?.containerHeight.constant = (cell?.containerView.subviews.first?.frame.size.height) ?? 80
}
let cellHeight = (cell?.upperView.bounds.height)! + (cell?.textView.bounds.height)! + (cell?.containerView.bounds.height)! + (cell?.lowerView.bounds.height)!
return CGSize(width: 375, height: cellHeight)
}
здесь. Это только для создания новых ячеек. В этом случае вы хотите получить существующую ячейку и, вероятно, должны использовать _2_ в классе _3_.