【问题标题】:FirebaseUI Firestore not retrieving data on iOSFirebaseUI Firestore 未在 iOS 上检索数据
【发布时间】:2018-08-28 13:36:55
【问题描述】:

FirebaseUI-Firestore iOS 的 documentation 不是很彻底,我已经实现了代码,但我的集合视图没有被填充:

class HomeViewController:UIViewController {

@IBOutlet weak var collectionView: UICollectionView!

var firestore:Firestore = Firestore.firestore()

override func viewDidLoad() {
    super.viewDidLoad()

    let query = firestore.collection("/offers")

    let dataSource = collectionView.bind(toFirestoreQuery: query) { (collectionView, indexPath, documentSnapshot) -> UICollectionViewCell in
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! OfferHolderCollection
        print("POPULATING")
        cell.myLabel?.text = documentSnapshot.data()?["name"] as? String
        return cell
    }        
}

在 Android 上,adapter.startListening() 方法将放在 onResume() 中以开始检索数据,但 iOS 似乎没有这种方法。上面的代码是否足以开始检索数据?

【问题讨论】:

    标签: ios firebase google-cloud-firestore firebaseui


    【解决方案1】:

    发现我的错误。来自 FirebaseUI 源代码 cmets:

    * The returned data source is not retained by the collection view and must be
    * retained or it will be deallocated while still in use by the collection view.
    

    确实,文档示例确实将其存储在 self.datasource 中,而我的代码将其存储在本地。因此,通过使数据源成为 ViewController 的成员来解决此问题。

    【讨论】:

      猜你喜欢
      • 2021-12-03
      • 1970-01-01
      • 2020-08-08
      • 2018-11-06
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2015-01-05
      • 2022-01-11
      相关资源
      最近更新 更多