我在UIViewController
中使用CollectionView
,此CollectionView
使用PinterestLayout。我现在已经有10件商品(1件是“+”图片和9件礼品图片)。当我点击这个saveButton
多加一个Gift
:不能将项目追加到CollectionView
它不会加载“托雷斯”的形象。
这是我在saveButton
行动代码:
func saveButtonTapped(sender: AnyObject) {
addViewIsShowed = false
let caption = addView.addTextView.text
let image = addView.addImageView.image!
let gift = Gift(caption: caption, image: image.decompressedImage)
// gifts.count is 10
gifts.append(gift)
// gifts.count is now 11
addView.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
collectionView.alpha = 1.0
saveButton!.removeFromSuperview()
collectionView.reloadData()
}
这里是CollectionViewDataSource方法:
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return gifts.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! GiftCollectionViewCell
cell.gift = gifts[indexPath.item]
return cell
}
那么你的'UICollectionViewDataSource'代码呢?似乎有一个问题 –
我已经添加了'UICollectionViewDataSource'方法..请再次检查。谢谢。 – Khuong
看起来没问题。你确定那些'UICollectionViewDataSource'是在你添加新的'Gift'后调用的吗? –