【发布时间】:2016-03-15 21:27:49
【问题描述】:
在我的收藏视图中添加额外的单元格时遇到问题 我已更改逻辑以使用数据模型来填充我的单元格
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
}
我认为问题出在这一行
让图片=图片[indexPath.item]为!图库
当我标记它并标记时
cell.image.sd_setImageWithURL(NSURL(string: picture.fileUrl), placeholderImage: UIImage(named: "Placeholder"))
它在第 11 位添加了额外的单元格。但其他方式让我超越了界限
谁能帮帮我?
【问题讨论】:
-
是的,在将
indexPath.item用作pictures的索引之前,您应该验证它是否小于pictures.count。你似乎有了答案。 -
@i_am_jorf no still index 10 beyond bounds [0 .. 9]
-
只需将该行移到
else语句中 -
@Paulw11 谢谢它的工作,我花了 2 个小时才明白什么坏了:)
标签: ios swift uicollectionview cell uicollectionviewcell