我使用的是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