I have a UICollectionView that displays cells from an array. I want the first cell to be a static cell that serves as a prompt to segue into a create flow (eventually adding a new cell).
My approach would have been to add two sections to my collectionView, but I currently can't figure out how to return a cell within cellForItemAtIndexPath if I do so. This is my attempt:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if indexPath.section == 0 {
let firstCell = collectionView.dequeueReusableCellWithReuseIdentifier("createCell", forIndexPath: indexPath) as! CreateCollectionViewCell
firstCell.imageView.backgroundColor = UIColor(white: 0, alpha: 1)
return firstCell
} else if indexPath.section == 1 {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("mainCell", forIndexPath: indexPath) as! MainCollectionViewCell
cell.imageView?.image = self.imageArray[indexPath.row]
return cell
}
}
The problem with this is that I have to return a cell at the end of the function. It seems that it won't be returned as part of an if condition. Thanks for helping!