2016-06-21 7 views
1

ビューコントローラにコレクションビューがあります。わからない問題が1つあります。コレクションビューのカスタムセルは、配列から1つの項目を表示しています。コレクションビューアレイから1つのアイテムのみを表示する

がコードに欠けているかを把握カント..私は、デリゲートとデータソース方式の両方を使用している...ここで

は、私が使用していたコード..です

viewDidLoad() 
pathRef.observeSingleEventOfType(.ChildAdded, withBlock: { (snapshot) in 
      let post = CollectionStruct(key: snapshot.key, snapshot: snapshot.value as! Dictionary<String, AnyObject>) 
      self.userCollection.append(post) 

      let indexPath = NSIndexPath(forItem: self.userCollection.count-1, inSection: 0) 
      self.collectionView!.insertItemsAtIndexPaths([indexPath]) 

     }) 



func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    return userCollection.count 
} 

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionCell", forIndexPath: indexPath) as! CollectionViewCell 

    let post = userCollection[indexPath.row] 


    if let imageUrl = post.category{ 

     if imageUrl.hasPrefix("gs://"){ 

      FIRStorage.storage().referenceForURL(imageUrl).dataWithMaxSize(INT64_MAX, completion: { (data, error) in 
       if let error = error { 

        print("Error Loading") 
       } 
       cell.userImg.image = UIImage.init(data: data!) 
      }) 


     }else if let url = NSURL(string: imageUrl), data = NSData(contentsOfURL: url){ 

      cell.userImg.image = UIImage.init(data: data) 
     } 
    } 
    return cell 
} 

私がしようとしていますfirebaseデータベースに格納されている画像を検索する。

+3

コードを表示できますか? –

+0

'userCollection'配列の数が1以上であることをチェックしましたか? –

+0

はい。配列内に10個以上のアイテムがあります。 –

答えて

0

observeSingleEventOfTypeの代わりにobserveEventTypeを使用する。 docsの詳細

+0

あなたは説明できますか? –

関連する問題