2016-04-22 2 views
2

の中にCollectionViewを使用しています。このCollectionViewはPinterestLayoutを使用しています。私はすでに10のアイテムを持っています(1つは "+"イメージ、9つはギフトイメージです)。私は追加するには、このsaveButtonをクリックすると1以上GiftCollectionViewにアイテムを追加できません

enter image description here

それは「トレス」の画像をロードしません。ここで

enter image description here

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 

} 
+0

あなたの 'UICollectionViewDataSource'コードはどうですか?そこに問題があると思われます。 –

+0

私は 'UICollectionViewDataSource'メソッドを追加しました。もう一度確認してください。ありがとう。 – Khuong

+0

いいですね。新しい 'Gift'を追加した後に' UICollectionViewDataSource'が呼び出されたことを確かめますか? –

答えて

1

あなたはあなたがしなければならないcollectionView内のデータをリフレッシュしたいときメインスレッドのリロードデータ

dispatch_async(dispatch_get_main_queue(),{ 
    collectionView.reloadData() 
}) 
+0

それは動作しません。 – Khuong

+0

私はそれを助けるためにもっとコードが必要です。あなたのUIViewControllerコードを置くことができれば素晴らしいかもしれません。ありがとう –

+0

私はちょうどそれらを追加しました。再度確認してください。ありがとう。 – Khuong

関連する問題