我有以下代码,它将集合视图放入一列或两列,具体取决于屏幕的大小:
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。我使用了两个 - 设置如下:
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
}
如何获取当前单元格的重用标识符,以便我可以根据它是什么类型的单元格来更改高度?