私はコレクションビューを持っています。私は各セルをプログラム的に一列にしたいと思っています。これまで私がこれまで行ってきたことは次のとおりです。コレクションセルの行のセルが迅速に処理されますか?
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.challenges.count
}
// make a cell for each cell index path
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// get a reference to our storyboard cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MyCollectionViewCell
cell.myLabel.text = self.challenges[indexPath.item]
cell.backgroundColor = .orange
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("You selected cell #\(indexPath.item)!")
}
}
class MyCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var myLabel: UILabel!
}
次に何をすればいいですか?すでにparentViewControllerにcollectionViewのデリゲートを設定するので、次のことを実行することである、これを行う最も簡単な方法を
:あなたは、各セルは、ビューの全体の幅を取るしたいと仮定すると、
あなたが上記の機能を見つけることができません。私は次のようにそれを書くことを試みた。しかし、私は文句を言わない、すべてで呼び出されます: FUNCのcollectionView(_ collectionView:UICollectionView、レイアウトcollectionViewLayout:UICollectionViewLayout、sizeForItemAt indexPath:IndexPath) - > CGSize { LETサイズ= CGSize(幅:UIScreen .main.bounds.width、height:10) 戻りサイズ; } –
上記の関数を含むviewcontrollerは 'UICollectionViewDelegateFlowLayout'プロトコルを実装していますか?もしそうなら、コレクションビューのデリゲートとして設定しましたか? – Houwert