我能夠創建類似於Instagram的UICollection View feed,但我不確定如何選擇單元格並轉到更詳細的視圖控制器。這是我的主視圖控制器的樣子。 「從主視圖控制器發送Firebase數據到詳細視圖控制器
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
}
})
以上就是我的詳細視圖控制器。但是,當單擊單元格時,我的信息不通過
嗨。請將您的代碼片段作爲文本發佈並相應地設置格式,而不是張貼屏幕截圖。 –
@AL。我已經發布了我的代碼片段作爲文本 – juelizabeth
您應該解析來自主ViewController中的Firebase的數據並將其傳遞給detailViewController – WeiJay