ios - Image change in UITableViewCell using Segmented control in another View -


how change iboutlet image set in uitableviewcell using segmented control in view controller using swift?

uitableviewcell.swift:

class usercell: uitableviewcell {      @iboutlet var imagedisplayicon: uiimageview! 

viewcontroller:

@ibaction func btnclicked(sender: anyobject) {      if txtsex.selectedsegmentindex == 0{          var imagepicview: usercell = usercell()          imagepicview.imagedisplayicon.image = uiimage(named: "boyicon.png")          //imagedisplay.image = uiimage(named: "boyicon.png")          print("male")      }      if txtsex.selectedsegmentindex == 1{           var imagepicview: usercell = usercell()          imagepicview.imagedisplayicon.image = uiimage(named: "girlicon1.png")          //imagedisplay.image = uiimage(named: "girlicon1.png")          print("female")      } 

i error saying

"fatal error: unexpectedly found nil while unwrapping optional value." 

what do??

i suppose have uitableview

1. reload table data in action

@ibaction func btnclicked(sender: anyobject) {     tableview.reloaddata() } 

2. add image cell in table data source delegate

func tableview(_ tableview: uitableview,     cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {      let imagename = txtsex.selectedsegmentindex == 0 ? "boyicon.png" : "girlicon1.png"      // load cell      cell.imagedisplayicon.image = uiimage(named: imagename)      return cell } 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -