我下面This Tutorial 和我面臨的問題類型「任何」有沒有下會員當我定義的ViewController.Swiftm我的標題和消息在等待你的一種建議
類型「任何」已經在Xcode 8.1沒有下成員斯威夫特3
import UIKit
import Firebase
import FirebaseDatabase
struct postStruct {
let title : String
let message : String
}
class TableViewController: UITableViewController {
let posts = [postStruct]()
override func viewDidLoad() {
super.viewDidLoad()
let databaseRef = FIRDatabase.database().reference()
databaseRef.child("posts").queryOrderedByKey().observe(.childAdded, with: { (snapshot) in
let title = snapshot.value!["title"] as! String
let message = snapshot.value!["message"] as! String
self.posts.insert(contentsOf: postStruct(title: title , message: message), at: index, 0)
self.tableView.reloadData()
})
post()
}
func post() {
let title = "Title"
let message = "Message"
let post:[String:AnyObject] = ["title":title as AnyObject,"message":message as AnyObject]
let databaseRef = FIRDatabase.database().reference()
databaseRef.child("posts").childByAutoId().setValue(post)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return posts.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
let label1 = cell?.viewWithTag(1) as! UILabel
label1.text = posts[indexPath.row].title
let label2 = cell?.viewWithTag(2) as! UILabel
label2.text = posts[indexPath.row].message
}
}
看起來你錯過了幾十個類似的問題和他們的答案存在,當你做了研究這個問題的問題... *咳嗽* – Moritz
@EricAya我看了十幾個第一。 –
@EricAya他們有些不同。 –