【发布时间】:2017-10-13 01:23:22
【问题描述】:
这是 firebase 节点帖子,我不知道为什么它是可选的。我认为是问题所在。
帖子:
可选(“hXCdzourFJNRLCH64GF7yZVzu0I3”) -Kj_auPDxdboKTgPV-9J 文字:你好
- 这是在 firebase 数据库中设置节点的 get
@IBOutlet weak var post: UIButton!
@IBOutlet weak var newpost: UITextView!
var databaseref = FIRDatabase.database().reference()
var loggedinuser : AnyObject?
override func viewDidLoad() {
super.viewDidLoad()
self.loggedinuser = FIRAuth.auth()?.currentUser
newpost.textContainerInset = UIEdgeInsetsMake(30, 20, 20, 20)
newpost.text = "what is new?"
newpost.textColor = UIColor.lightGray
}
@IBAction func didtapcancel(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
func didbeganediting(_ textView : UITextView) {
if(newpost.textColor == UIColor.lightGray){
newpost.text = ""
newpost.textColor = UIColor.black
}
}
func textFieldShouldReturn(_ textfield: UITextField) -> Bool {
textfield.resignFirstResponder()
return false
}
func didtappost(_ sender: Any) {
if (newpost.text.characters.count>0) {
let key = databaseref.child("posts").childByAutoId().key
let childupdates = ["/posts/\(self.loggedinuser!.uid)/\(key)/text ": newpost.text,"/time/\(self.loggedinuser!.uid)/\(key)/text":"\(Date().timeIntervalSince1970)"] as [String : Any]
self.databaseref.updateChildValues(childupdates)
dismiss(animated: true, completion: nil)
}
}
}
这是表格视图代码:
@IBOutlet weak var ac: UIActivityIndicatorView!
@IBOutlet weak var feeds: UITableView!
var databaseref = FIRDatabase.database().reference()
var loggedinuser : AnyObject?
var loggedinuserdata : NSDictionary?
var posts = [NSDictionary]()
override func viewDidLoad() {
super.viewDidLoad()
self.loggedinuser = FIRAuth.auth()?.currentUser
self.databaseref.child("users").child(self.loggedinuser!.uid).observeSingleEvent(of: .value) { (snapshot:FIRDataSnapshot) in
self.loggedinuserdata = snapshot.value as? NSDictionary
self.databaseref.child("posts").child(self.loggedinuser!.uid).observe(.childAdded, with: { (snapshot: FIRDataSnapshot) in
self.posts.append(snapshot.value as! NSDictionary)
self.feeds.insertRows(at: [IndexPath(row : 0 ,section : 0)], with: UITableViewRowAnimation.automatic)
self.ac.stopAnimating()
}) {(error) in
print(error.localizedDescription)
}
}
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.posts.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : viewTableViewCell = tableView.dequeueReusableCell(withIdentifier: "opa", for:indexPath) as! viewTableViewCell
let post = posts[(self.posts.count-1) - indexPath .row]["text"] as! String
cell.configure(nil, name:self.loggedinuserdata!["name"] as! String
handle: self.loggedinuserdata!["handle"] as! String, post: post)
return cell
}
【问题讨论】:
-
那个节点在哪里设置?
-
节点正在firebase中设置我不明白你的问题
-
@PeterTao 这是设置firebase节点帖子的代码检查问题中的最后更新
标签: ios uitableview firebase swift3