ios - Sync Checkmarks Between UISearchController and FetchRequest -


i'm trying sync accessorytype.checkmark between search view , non-search view. i've tried setting cell.accessorytype = .none in few different spots on cellforrowatindexpath, yet keep getting random checkmarks when switch between fetchedresults , search results. don't know i'm screwing up, rest assured it'll startlingly stupid.

i have uitableviewcontroller that's set up. when loads, have configured display items nsfetchrequest. works perfectly.

i have uisearchcontroller that's set up. works , displays results want.

i encounter problem of random checkmarks appearing when toggle between search , fetchrequest. array of stuff save working , right items in there---it's checkmarks getting ****ed up. feedback appreciated. i'm out of ideas.

here relevant properties i've got declared before viewdidload in uitableviewcontroller class:

// create array dump fetchresults var unfilteredjingles = [jingle]()  // create array store filtered search results var filteredjingles = [jingle]()  // array ones want save added/removed var jinglestosave = [jingle]()  // resultssearchcontroller var resultssearchcontroller = uisearchcontroller() 

when cells selected, have didselectrowatindexpath configured 2 things:

1) append jinglestosave cell array , place checkmark next cell. works.

2) remove jinglestosave cell jinglestosave array. works, too.

the issue i'm encountering random cells getting checked when switch between searchresultscontroller.active , searchresultscontroller not active. correct cells staying checked, random ones checked.

here's cellforrowatindexpath:

override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecellwithidentifier("jinglecell", forindexpath: indexpath)      // instantiate local array , assign filtered/unfiltered results based on whether     // resultssearchcontroller active     var jinglearray = [jingle]()      if resultssearchcontroller.active {         // set local array filtered array         jinglearray = filteredjingles         let jingle = jinglearray[indexpath.row]         // set labels cell         cell.textlabel?.text = jingle.jingledescription         cell.detailtextlabel?.text = jingle.jinglestar      } else {         // set local array un-filtered array         jinglearray = unfilteredjingles         // jingle index         let jingle = jinglearray[indexpath.row]         // set labels cell         cell.textlabel?.text = jingle.jingledescription         cell.detailtextlabel?.text = jingle.jinglestar     }      // set checkmarks     if self.jinglestosave.count > 0 {         // enumerate jinglestosave...         (indexofjinglestosave, jingletosave) in jinglestosave.enumerate() {             // if object in array of stuff save matches object in index of tableview             if jinglearray[indexpath.row].hashvalue == jinglestosave[indexofjinglestosave].hashvalue {                 // set accessoryview checkmark                 cell.accessorytype = .checkmark             }         }     }      return cell } 

reset cells checkmark state default state (im guessing no checkmark) after dequeue cell. cell recycling issue checkmarks appearing on cells shouldnt on.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -