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:
- your array
anime(yes it'sanimeshould use lowercase first char) hasnelementsnnumber of cells in table - each element of
animetuple - the first element of
tuple(declared @ bullet 2)stringrepresenting 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
0in section0(the first cell in table)indexpathhaverowproperty equals0,sectionequals0. cell1in section0, index path haverowequals1,sectionequals0. , 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
Post a Comment