我正在尝试在按下segue时从Firebase发送数据。但是,每当我点击UITableViewCell时,我都会收到错误"意外地发现nil,同时展开一个Optional值"在FIRDatabase.database().reference().child("posts").child(postDetails!).observeSingleEvent(of: .value, with: { (snapshot) in
这是我的prepareForSegue
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject) {
if (segue.identifier == "showDetails") {
let detailsViewController = segue.destination as! PostDetailsViewController
let indexPath = self.postsTableView.indexPathForSelectedRow
let post = self.posts[(indexPath?.row)!] as! [String: AnyObject]
detailsViewController.postDetails = post["postID"] as? String
}
}
这是我试图将数据传递给
的单独的ViewControllervar postDetails: String?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
FIRDatabase.database().reference().child("posts").child(postDetails!).observeSingleEvent(of: .value, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
self.priceLabel.text = dictionary["price"] as? String
}
})
}
我在这里做错了什么可能导致这个?