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数据库中的图像..
你能显示你的代码吗? –
你有没有检查你的'userCollection'数组的数量是否大于1? –
是的..有一个数组中有超过10个项目.. –