ios - Using segmented control to switch tableView -
i'm trying change table view cell when segmented control changed here have
internal func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { var returnvalue = 0 switch(segmentedc.selectedsegmentindex) { case 0: returnvalue = rest.count break case 1: returnvalue = fullmenu.count break default: break } return returnvalue }
i have numberofrowsinsection
, cellforrowatindexpath
func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { var cell = tableview.dequeuereusablecellwithidentifier("food") as! resttableviewcell var cell2 = tableview.dequeuereusablecellwithidentifier("fullm") as! fullmenutableviewcell switch(segmentedc.selectedsegmentindex) { case 0: let res: rest! res = rest[indexpath.row] var img: uiimage? if let urls = foo.imagestring{ img = foodviewcontroller.imagecache.objectforkey(urls) as? uiimage } dispatch_async(dispatch_get_main_queue()) { cell.setupviews(res) } break case 1: cell2.textlabel?.text = fullmenu[indexpath.row] break default: break } return cell }
also have ibaction
segmented control
@ibaction func seg(sender: anyobject) { switch(segmentedc.selectedsegmentindex) { case 0: tableview.reloaddata() break case 1: tableview.reloaddata() break default: break } }
but when change segment 1 cell index 0
show in index 1
in cellforrowatindexpath returning cell never returning cell2. try returning cell2 in second case.
func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { var cell = tableview.dequeuereusablecellwithidentifier("food") as! resttableviewcell var cell2 = tableview.dequeuereusablecellwithidentifier("fullm") as! fullmenutableviewcell switch(segmentedc.selectedsegmentindex) { case 0: let res: rest! res = rest[indexpath.row] var img: uiimage? if let urls = foo.imagestring{ img = foodviewcontroller.imagecache.objectforkey(urls) as? uiimage } dispatch_async(dispatch_get_main_queue()) { cell.setupviews(res) } break case 1: cell2.textlabel?.text = fullmenu[indexpath.row] return cell2 break default: break } return cell }
Comments
Post a Comment