0
私が読んだ私はきちんとセルをdequedとcollectionView.cellForItemは(時:indexPath)正常に動作していない
それを返した 、collectionView?.register(ActivityCell.self, forCellWithReuseIdentifier: cellId)
、私のcollectionViewController私は正しく私のセルを登録したUICollectionViewDelegateFlowLayout、 のデリゲート作ら
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: ActivityCell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! ActivityCell
return cell
}
が、私はsizeForItemAtIndexPath機能でindexPathを用いて細胞を取得しようとするたびに、それは
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if let cell: ActivityCell = self.collectionView?.cellForItem(at: indexPath) as? ActivityCell
{
let approximatewidthofcell = view.frame.size.width - 50
let size = CGSize(width: approximatewidthofcell, height: 1000)
let attributes = [NSFontAttributeName: UIFont.systemFont(ofSize: 15)]
let estimatedframe = NSString(string: cell.activitylabel.text!).boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: attributes, context: nil)
return CGSize(width: view.frame.size.width, height: estimatedframe.height)
}
else
{
return CGSize(width: view.frame.size.width, height: 200)
}
}
活動セルを返すdoesntのI fブロックは常に無視されますが、elseブロックは毎回実行されますが、次にどのようなコードを操作するのか分かりません。
私はsilentbobを知っている限り、collectionVCにはデータソースを割り当てる必要はありません。シンプルなビューコントローラではデータソースidkが必要なものがあります。 –
こんにちは、忙しい週... なぜself.collectionViewの代わりにcollectionViewの引数を使用しないのですか? – silentBob