I have an issue to add extra cell to my collection view I have change a logic to use data model to fill my cells
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return pictures.count + 1
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("images", forIndexPath: indexPath) as! ProfileImageCell
let picture = pictures[indexPath.item] as! Gallery
print(indexPath.item)
if indexPath.item == pictures.count {
cell.image.image = UIImage(named: "ProfilePlusImage")
} else {
cell.image.sd_setImageWithURL(NSURL(string: picture.fileUrl), placeholderImage: UIImage(named: "Placeholder"))
cell.imageId = picture.id.integerValue
}
return cell
}
The issue is in this line I think
let picture = pictures[indexPath.item] as! Gallery
When I mark it and mark
cell.image.sd_setImageWithURL(NSURL(string: picture.fileUrl), placeholderImage: UIImage(named: "Placeholder"))
It adding extra cell on 11-th place. But other way gives my beyond bounds
Could anyone help me?
indexPath.item
is less thanpictures.count
before you use it as an index intopictures
. You seem to have the answer. – i_am_jorfelse
statement – Paulw11