c# - TableView RowSelected with SearchResultsTableView: Keeping Track of Cell Index for CheckMark -


i have tableview i've created json file keeps track of checked/unchecked status of cell. problem when implemented searchresults view, results skewed because check cell @ index path, , update corresponding json entry (subscribestatus).

 var cell = tableview.cellat(indexpath); 

wondering if there way modify, or figure out approach takes account correct index search results displayed. here sample code below:

public override void rowselected(uitableview tableview,nsindexpath indexpath)     {         var cell = tableview.cellat(indexpath);         var value = this.tableviewcontroller.tableview==search.searchresultstableview ? filtereddatalist[indexpath.row] : datalist[indexpath.row];          if (value.selected)         {             value.selected = false;              var uncheckedimage = new uiimageview (uiimage.frombundle("unchecked"));              cell.accessoryview = uncheckedimage;             string documentspath = environment.getfolderpath (environment.specialfolder.mydocuments);               var localpath = path.combine (documentspath, "marketnibble_sample_customers.json");             string json = file.readalltext (localpath);             dynamic jsonobj = newtonsoft.json.jsonconvert.deserializeobject (json);             jsonobj ["business"] [indexpath.row] ["subscribestatus"] = false;             string output = newtonsoft.json.jsonconvert.serializeobject (jsonobj);             file.writealltext (localpath, output);          }         else         {             value.selected = true;              var checkedimage = new uiimageview (uiimage.frombundle("checked"));             cell.accessoryview = checkedimage;              string documentspath1 = environment.getfolderpath(environment.specialfolder.mydocuments);              var localpath1 = path.combine(documentspath1, "marketnibble_sample_customers.json");             string json = file.readalltext(localpath1);             dynamic jsonobj = newtonsoft.json.jsonconvert.deserializeobject (json);             jsonobj["business"][indexpath.row]["subscribestatus"] = true;             string output = newtonsoft.json.jsonconvert.serializeobject(jsonobj);             file.writealltext (localpath1, output);          }         cell.selected = false;         tableviewcontroller.tableview.reloaddata ();     } 

i've heard of way cell.tag(), don't have clue begin. best way approach this?

you need way other indexpath map cell it's underlying data. can use tag property - tag string can use whatever like. easiest approach store id or key property of json element in tag, , whenever cell selected, can use tag proprerty find underlying data in json , update appropriately.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -