【发布时间】:2017-03-08 19:19:10
【问题描述】:
我能够创建类似于 Instagram 的 UICollection 视图提要,但我不确定如何选择单元格并转到更详细的视图控制器。这是我的主视图控制器的样子。 '
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
performSegue(withIdentifier: "details", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "details" {
if let indexPaths = self.collectionView!.indexPathsForSelectedItems{
let vc = segue.destination as! MainViewController
let indexPath = indexPaths[0] as NSIndexPath
let post = self.posts[indexPath.row] as! [String: AnyObject]
let Booked = post["title"] as? String
let Authors = post["Author"] as? String
let ISBNS = post["ISBN"] as? String
let Prices = post["Price"] as? String
let imageNames = post["image"] as? String
vc.Booked = Booked
vc.Authors = Authors
vc.ISBNS = ISBNS
vc.Prices = Prices
vc.imageNames = imageNames
print(indexPath.row)
} }}
这是我的数据库的样子:
//Detailed View Controller
FIRDatabase.database().reference().child("posts").child(self.loggedInUser!.uid).observeSingleEvent(of: .value, with: { (snapshot:FIRDataSnapshot) in
if let dictionary = snapshot .value as? [String: AnyObject] {
self.BookTitle.text = dictionary["title"] as? String
self.Author.text = dictionary["Author"] as? String
self.ISBN.text = dictionary["ISBN"] as? String
self.Price.text = dictionary["Price"] as? String
self.Image.image = ["image"] as? UIImage
}
})
上面是我的详细视图控制器。但是,当我单击单元格时,我的信息没有通过
【问题讨论】:
-
嗨。请将您的代码 sn-ps 发布为文本并相应地格式化它们,而不是发布屏幕截图。
-
@AL。我已将我的代码 sn-ps 发布为文本
-
你应该在 Main ViewController 中解析来自 firebase 的数据并将其传递给 detailViewController
-
您的代码只是显示您从 detailViewController 中的 firebase 解析数据。换句话说,你没有任何东西可以传递给你的 detailViewController
标签: ios swift firebase firebase-realtime-database uicollectionviewcell