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