ios - Select Cells on viewdidload in UITableView, based on String Array (Swift) -


how can select multiples cell in uitableview based on match string value within core data array?

i have saved previous selected rows (as string), when load table again, want selected again. can't find or think of solution this.

array:

 var category:[string] = ["news", "sport", "weather", "earth", "future", "shop", "tv", "radio", "food", "music", "travel", "local", "nature", "venue", "money"] 

i try figure out selectrowatindexpath didn't see in swift.

here how fetch data core data

func fetchdata(){         let entitydescription = nsentitydescription.entityforname("usersettings", inmanagedobjectcontext: context!)         let request = nsfetchrequest()         request.entity = entitydescription         var dataobjects: [anyobject]?         {             dataobjects = try context?.executefetchrequest(request)         } catch  let error nserror {             print(error)             dataobjects = nil         }          //can update table selection fetch?         result in dataobjects as! [nsmanagedobject] {          print(result.valueforkey("favcategory")!)          }     } 

update how can select base on string stored in core data (multiple selection on viewdidload)

 let rowtoselect:nsindexpath = nsindexpath(forrow: 0, insection: 0);  //slecting 0th row 0th section  self.tableview.selectrowatindexpath(rowtoselect, animated: true, scrollposition: uitableviewscrollposition.none); 

you can not select cells on viewdidload because tableview not loaded of yet in viewdidload. should store bool variable flag in datasource, update cellforrowatindexpath: method as:

override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecellwithidentifier("cell", forindexpath: indexpath) as! yourcustomcell      let object = self.dataobjects[indexpath.row] as! yourobject     cell.selected = object.isselected      return cell } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -