の中にCollectionView
を使用しています。このCollectionView
はPinterestLayoutを使用しています。私はすでに10のアイテムを持っています(1つは "+"イメージ、9つはギフトイメージです)。私は追加するには、このsaveButton
をクリックすると1以上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
いいですね。新しい 'Gift'を追加した後に' UICollectionViewDataSource'が呼び出されたことを確かめますか? –