ios - How to transfer Image from tableview to second view -


i have table view image in each cell. want pass image second view controller when user selects cell. set segue cell second view controller.

my code produces nil image in second view controller.

i'm sure i'm supposed use delegates , found plenty of examples pass them first view controller non way. haven't got clue how set up.

can give me example?

tableview (first view controller)

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {     if segue.identifier == "imagecropsegue"{         if let destination = segue.destinationviewcontroller as? cropimageview {             if let profileindex = self.parsetable.indexpathforselectedrow()?.row {                 var index = nsindexpath(forrow: profileindex, insection: 0)                  var cell = self.parsetable.cellforrowatindexpath(index) as! tableviewcell                 destination.cropimage.image = cell.cellimage.image //throws exception destination.cropimage = nil             }         }      } } 

second view controller

class cropimageview:uiviewcontroller{     @iboutlet weak var cropimage: uiimageview!     override func viewdidload() {         super.viewdidload()      } }  

second view controller:

 class cropimageview:uiviewcontroller{     @iboutlet weak var cropimage: uiimageview!     var selectedimage : uiimage?     override func viewdidload() {         super.viewdidload()         self.cropimage.image = self.selectedimage //assign selected image here      } }  

prepareforsegue method in firstview controller like:

 override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {     if segue.identifier == "imagecropsegue"{         if let destination = segue.destinationviewcontroller as? cropimageview {             if let profileindex = self.parsetable.indexpathforselectedrow()?.row {                 var index = nsindexpath(forrow: profileindex, insection: 0)                  var cell = self.parsetable.cellforrowatindexpath(index) as! tableviewcell                 //destination.cropimage.image = cell.cellimage.image //change here                 destination.selectedimage= cell.cellimage.image             }         }      } } 

Comments