gpt4 book ai didi

xcode - 从新的 Firebase(数据库)中检索数据

转载 作者:搜寻专家 更新时间:2023-11-01 05:36:40 26 4
gpt4 key购买 nike

我无法从新的 Firebase 检索数据。在我触摸按钮(act())之后没有任何变化。我检查了所有设置并阅读了 Firebase 网站中的所有文档,但我不明白为什么什么都没有发生。

    import UIKit
import Firebase

var ref = FIRDatabaseReference.init()

class MainTovarViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
@IBOutlet weak var collectionView: UICollectionView!
var items = [FIRDataSnapshot]()
override func viewDidAppear(animated: Bool) {

}
override func viewDidLoad() {
super.viewDidLoad()
ref = FIRDatabase.database().reference()

}


@IBAction func act(sender: AnyObject) {
ref.observeEventType(FIRDataEventType.Value) { (snapshot: FIRDataSnapshot!) in

var newItems = [FIRDataSnapshot]()
for item in snapshot.children {
newItems.append(item as! FIRDataSnapshot)
}

self.items = newItems
print("\(self.items)")
self.collectionView!.reloadData()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
var result = 0
if items.count != 0 {
result = items.count
}
return result
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MainTovarCollectionCell", forIndexPath: indexPath) as! MainTovarCollectionCellCollectionViewCell
cell.backgroundView = UIImageView(image: UIImage(named: "product_1"))
cell.titletovar.text = items[indexPath.row].value!.objectForKey("TovarName") as! String

return cell
}

}

还有这个:

2016-05-21 10:55:38.340 shoroo[95390:14237917] WARNING: Firebase 

Analytics App Delegate Proxy is disabled. To log deep link campaigns manually, call the methods in FIRAnalytics+AppDelegate.h.
2016-05-21 10:55:38.510 shoroo[95390:14237917] Configuring the default app.
2016-05-21 10:55:38.522 shoroo[95390:] <FIRAnalytics/INFO> Firebase Analytics v.3200000 started
2016-05-21 10:55:38.523 shoroo[95390:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled
2016-05-21 10:55:38.529: <FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
2016-05-21 10:55:38.533: <FIRMessaging/INFO> FIRMessaging library version 1.1.0
2016-05-21 10:55:38.564 shoroo[95390:] <FIRAnalytics/INFO> Firebase Analytics enabled
Error Domain=NSCocoaErrorDomain Code=3010 "REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION" UserInfo={NSLocalizedDescription=REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION}

最佳答案

检查您的数据库授权(规则)。尝试将规则设置为:

{
"rules": {
".read": true,
".write": true
}
}

关于xcode - 从新的 Firebase(数据库)中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37360429/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com