ios - Swift adding image icons to UITableViewController -


i trying import separate image icons next tableview cells using code

switch(anime)   {     case 0:                var bleachimage = uiimage(named: "bleach icon")         cell.imageview?.image  = bleachimage     } 

but keep getting error marked @ case 0 saying type int not conform protocol intervaltype.

i'm using swift way xcode 6.1

i read before posting supposed switching cell index not array, tried , failed maybe i'm doing wrong?

thx help.

assuming that:

  1. your array anime (yes it's anime should use lowercase first char) has n elements n number of cells in table
  2. each element of anime tuple
  3. the first element of tuple (declared @ bullet 2) string representing name of image locally stored

you can add image each cell code:

override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecellwithidentifier("mycell") as? uitableviewcell         ?? uitableviewcell(style: .default, reuseidentifier: "mycell")     let tuple = self.anime[indexpath.row]     cell.imageview?.image = uiimage(named: tuple.0)     return cell } 

hope helps.

update better answer comment

the method above called ios every cell needs displayed. each time called indexpath referring specific cell.

e.g. if ios need display cell 0 in section 0 (the first cell in table) indexpath have row property equals 0 , section equals 0. cell 1 in section 0, index path have row equals 1 , section equals 0. , on...

so, doing inside method? accessing element indexpath.row of array anime, in order retrieve tuple needed populate cell @ position indexpath.row. next extract first element of tuple (a string containing name of image) , use value build uiimage. next assign image current cell. return cell.

just try it. if assumptions correct, work.


Comments