2
這是我在得到一個錯誤的行:錯誤說「類型的值‘FIRDatabaseReference’沒有成員‘觀察’」
databaseHandle = ref.child("Posts").observe(.childAdded, withBlock: { (snapshot) in
self.postData.append("")
})
下面是所有的代碼...
import UIKit
import FirebaseDatabase
class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet
var tableView: UITableView!
var ref: FIRDatabaseReference!
var databaseHandle: FIRDatabaseHandle ?
var postData = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
tableView.delegate = self
tableView.dataSource = self
ref = FIRDatabase.database().reference()
databaseHandle = ref.child("Posts").observe(.childAdded, withBlock: {
(snapshot) in
self.postData.append("")
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func JumpTabLive(sender: AnyObject) {
tabBarController ? .selectedIndex = 1
}
@IBAction func JumpTabLocal(sender: AnyObject) {
tabBarController ? .selectedIndex = 2
}
@IBAction func JumpTabOnline(sender: AnyObject) {
tabBarController ? .selectedIndex = 3
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) - > Int {
return postData.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) - > UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("PostCell")
cell ? .textLabel ? .text = postData[indexPath.row]
return cell!
}
}
謝謝你的迴應。我用Block更改爲,但仍然收到相同的錯誤信息 –
使用自動完成建議我能夠使其工作。代碼結束爲:databaseHandle = ref.child(「Posts」)。observeEventType(.ChildAdded,withBlock:{(snapshot)in self.postData.append(「」)...謝謝你的幫助! –
哦!可能我們使用的是不同版本的Firebase SDK,不管怎樣,以後只需使用Xcode的自動完成/建議:D很高興現在解決它了。您可以選擇這個作爲您的文章的答案嗎? – Glenn