画面のサイズに応じて、コレクション ビューを 1 つまたは 2 つの列に配置する次のコードがあります。
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let size = collectionView.frame.width
if (size > 500) {
return CGSize(width: (size/2) - 8, height: (size/2) - 8)
}
return CGSize(width: size, height: size)
}
これを修正したいので、高さはreuseIdentifierに依存します。私が使用するものは2つあります-次のように設定します:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let diceRoll = Int(arc4random_uniform(2) + 1)
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("profileViewCell", forIndexPath: indexPath)
if(diceRoll == 1) {
cell = collectionView.dequeueReusableCellWithReuseIdentifier("profileChartViewCell", forIndexPath: indexPath)
}
return cell
}
セルのタイプに応じて高さを変更できるように、現在のセルの reuseIndentifier を取得するにはどうすればよいですか?