ios - Swift 3 Segue from UICollectionView Cell -
hi i'm beginner , stuck on basic segue! want find out correct syntax use sender e.g sandals[indexpath.row]sandalname thanks
override func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell { let cell = collectionview.dequeuereusablecell(withreuseidentifier: "cell", for: indexpath) as! shoecollectionviewcell let sandalcell = sandals[indexpath.row] cell.sandalimage.image = uiimage(named: sandalcell["image"]!) cell.sandalstylename.text = sandalcell["stylename"] cell.sandalprice.text = sandalcell["price"] return cell } override func prepare(for segue: uistoryboardsegue, sender: any?) { if segue.identifier == "shoedetailsegue"{ var detailpage = segue.destination as! shoedetailviewcontroller let selectedcell = sender as! uicollectionviewcell let indexpath = collectionview?.indexpath(for: cell) detailpage.getname = sandals[indexpath!.row].sandalname detailpage.getprice = sandals[indexpath!.row].sandalprice detailpage.getimage = sandals[indexpath!.row].sandalimage } }
if want pass value segue need access array subscript
same way doing in cellforitemat
.
override func prepare(for segue: uistoryboardsegue, sender: any?) { if segue.identifier == "shoedetailsegue"{ var detailpage = segue.destination as! shoedetailviewcontroller let selectedcell = sender as! uicollectionviewcell let indexpath = collectionview?.indexpath(for: cell) let sandal = sandals[indexpath!.row] detailpage.getname = sandal["stylename"]! detailpage.getprice = sandal["price"]! detailpage.getimage = uiimage(named: sandal["image"]!) } }
Comments
Post a Comment