xcode - How to load images from Images.xcassets into a UIImage -


i trying code images uiimage having trouble. not sure how code each different image per list item. app building list pictures attached each list item.

below mywhatsit class:

class mywhatsit {  var name: string {     didset {         postdidchangenotification()     } } var location: string {     didset {         postdidchangenotification()     } } var image: uiimage? {     didset {         postdidchangenotification()     } } var viewimage: uiimage {     return image ?? uiimage(named: "camera")! }  init( name: string, position: string = "" ) {     self.name = name     self.location = location }  func postdidchangenotification() {     let center = nsnotificationcenter.defaultcenter()     center.postnotificationname(whatsitdidchangenotification, object: self) }  } 

below table view:

override func numberofsectionsintableview(tableview: uitableview) -> int {     return 1 }  override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {     return things.count }  override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath)     let thing = things[indexpath.row] mywhatsit     cell.textlabel?.text = thing.name     cell.detailtextlabel?.text = thing.location     cell.imageview?.image = thing.viewimage     return cell }  override func tableview(tableview: uitableview, caneditrowatindexpath indexpath: nsindexpath) -> bool {     // return false if not want specified item editable.     return true }  override func tableview(tableview: uitableview, commiteditingstyle editingstyle: uitableviewcelleditingstyle, forrowatindexpath indexpath: nsindexpath) {     if editingstyle == .delete {         things.removeatindex(indexpath.row)         tableview.deleterowsatindexpaths([indexpath], withrowanimation: .fade)     } else if editingstyle == .insert {         // create new instance of appropriate class, insert array, , add new row table view.     } } 

i believe need create array of images title , subtitle. when add picture, add image name array , append tableview.

what see in code name , position. looks need add "image" , set name of image. example, mywhatsit(name: "bob smith", position: "midfielder", image: "bobsmithimage")... , set cell's image view equal image name.

hope gets moving!


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -