我使用的是Firebase实时数据库,它对我应用程序的某些部分工作正常。我正在阅读YouTube上的一个教程,该教程向用户填充collectionView。它使用NSDictionary获取照片URL和用户名,并将它们放入所有用户的集合视图中。我直接在Firebase控制台中删除了部分用户,现在只有一个用户。出于某种原因,它仍在拉我删除的用户。这是collectionView文件。firebase正在检索从数据库中删除的数据
import UIKit
import FirebaseDatabase
private let reuseIdentifier = "UserSearchCell"
class UsersCollectionViewController: UICollectionViewController {
var usersDict = NSDictionary?()
var userNamesArray = [String]()
var userImagesArray = [String]()
override func viewDidLoad() {
super.viewDidLoad()
DataService.ds.REF_USERS.observeEventType(.Value, withBlock :{
(snapshot) in
self.usersDict = snapshot.value as? NSDictionary
for(userId,details) in self.usersDict!{
let img = details.objectForKey("profileThumbUrl") as! String
let name = details.objectForKey("username") as! String
self.userImagesArray.append(img)
self.userNamesArray.append(name)
self.collectionView?.reloadData()
}
})
self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.userImagesArray.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! UserSearchCell
let imageUrl = NSURL(string:userImagesArray[indexPath.row])
let imageData = NSData(contentsOfURL: imageUrl!)
cell.userImage.image = UIImage(data:imageData!)
cell.userName.text = userNamesArray[indexPath.row]
return cell
}
}
不应该这样总是与数据库同步?这些被删除的用户来自哪里?此外,我没有包含单元代码,因为它只是声明了imageView和Label操作。我之前遇到过这个问题,但是我的记忆很糟糕,我不记得为什么这样做,或者我曾经解决过这个问题。
模拟器!他们造成世界上一半的问题:) – Fattie
下午好!我现在正面临着一个真实设备上的这个问题。但我已经包含在缓存firebase – Alexander
然后,如果您禁用此功能FIRDatabase.database(),一切正常工作。 PersistenceEnabled。也许这是我的其他问题的答案,我会检查。 – Alexander