ios - Search through custom objects with UISearchController -
i'm trying create uisearchcontroller search through custom team objects , add , remove them in filteredarray. seem experience weird behaviour can't seem solve. tableview instance below:

and when instance search on "copen" returns:

why selected should not be?
my code:
override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier("teamcell", forindexpath: indexpath) as! teamcell if (self.teamsearchcontroller.active) { let team = filteredtabledata[indexpath.row] as! team cell.textlabel?.text = filteredtabledata[indexpath.row].name } else { let team = self.teamarray[indexpath.row] team cell.textlabel?.font = uifont(name: "helveticaneue-light", size: 20) cell.textlabel?.text = self.teamarray[indexpath.row].name string } var removed = false (index, value) in enumerate(self.teamselected) { if (value.id == team.id) { cell.accessoryview = cell.accessorycheck removed = true } } if (!removed) { cell.accessoryview = cell.accessoryuncheck } cell.selectionstyle = uitableviewcellselectionstyle.none return cell } updatesearchcontroller
func updatesearchresultsforsearchcontroller(searchcontroller: uisearchcontroller) { filteredtabledata.removeall(keepcapacity: false) let searchpredicate = nspredicate(format: "name contains[c] %@ or shortname contains[c] %@", searchcontroller.searchbar.text, searchcontroller.searchbar.text) let array = (teamarray nsarray).filteredarrayusingpredicate(searchpredicate) as! [team] filteredtabledata = array self.tableview.reloaddata() } lldb error:
* thread #1: tid = 0x1a4be2, 0x0000000106e7d52c libswiftcore.dylib`function signature specialization <arg[0] = exploded, arg[1] = exploded, arg[2] = dead, arg[3] = dead> of swift._fatalerrormessage (swift.staticstring, swift.staticstring, swift.staticstring, swift.uint) -> () + 44, queue = 'com.apple.main-thread', stop reason = exc_bad_instruction (code=exc_i386_invop, subcode=0x0) frame #0: 0x0000000106e7d52c libswiftcore.dylib`function signature specialization <arg[0] = exploded, arg[1] = exploded, arg[2] = dead, arg[3] = dead> of swift._fatalerrormessage (swift.staticstring, swift.staticstring, swift.staticstring, swift.uint) -> () + 44 * frame #1: 0x000000010484c548 striky`striky.teamviewcontroller.tableview (tableview=0x00007fe402887000, indexpath=0xc000000000000016, self=0x00007fe401d4ec20)(objectivec.uitableview, cellforrowatindexpath : objectivec.nsindexpath) -> objectivec.uitableviewcell + 3592 @ teamviewcontroller.swift:181 frame #2: 0x000000010484c94f striky`@objc striky.teamviewcontroller.tableview (striky.teamviewcontroller)(objectivec.uitableview, cellforrowatindexpath : objectivec.nsindexpath) -> objectivec.uitableviewcell + 79 @ teamviewcontroller.swift:0 frame #3: 0x0000000105beaa28 uikit`-[uitableview _createpreparedcellforglobalrow:withindexpath:willdisplay:] + 508 frame #4: 0x0000000105bc9248 uikit`-[uitableview _updatevisiblecellsnow:isrecursive:] + 2853 frame #5: 0x0000000105bdf8a9 uikit`-[uitableview layoutsubviews] + 210 frame #6: 0x0000000105b69a2b uikit`-[uiview(calayerdelegate) layoutsublayersoflayer:] + 536 frame #7: 0x0000000104fe1ec2 quartzcore`-[calayer layoutsublayers] + 146 frame #8: 0x0000000104fd66d6 quartzcore`ca::layer::layout_if_needed(ca::transaction*) + 380 frame #9: 0x0000000104fd6546 quartzcore`ca::layer::layout_and_display_if_needed(ca::transaction*) + 24 frame #10: 0x0000000104f42886 quartzcore`ca::context::commit_transaction(ca::transaction*) + 242 frame #11: 0x0000000104f43a3a quartzcore`ca::transaction::commit() + 462 frame #12: 0x0000000104f440eb quartzcore`ca::transaction::observer_callback(__cfrunloopobserver*, unsigned long, void*) + 89 frame #13: 0x00000001053e1ca7 corefoundation`__cfrunloop_is_calling_out_to_an_observer_callback_function__ + 23 frame #14: 0x00000001053e1c00 corefoundation`__cfrunloopdoobservers + 368 frame #15: 0x00000001053d7a33 corefoundation`__cfrunlooprun + 1123 frame #16: 0x00000001053d7366 corefoundation`cfrunlooprunspecific + 470 frame #17: 0x0000000108b30a3e graphicsservices`gseventrunmodal + 161 frame #18: 0x0000000105ae9900 uikit`uiapplicationmain + 1282 frame #19: 0x0000000104846c57 striky`main + 135 @ appdelegate.swift:13 frame #20: 0x0000000108094145 libdyld.dylib`start + 1 frame #21: 0x0000000108094145 libdyld.dylib`start + 1
the team selected because let team = self.teamarray[indexpath.row] team indexpath.row == 0 returns cloud9 , not wolves. fix team filteredtabledata follow
override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecellwithidentifier("teamcell", forindexpath: indexpath) as! teamcell var team : team! if (self.teamsearchcontroller.active) { team = filteredtabledata[indexpath.row] as! team cell.textlabel?.text = team.name } else { team = self.teamarray[indexpath.row] team cell.textlabel?.font = uifont(name: "helveticaneue-light", size: 20) cell.textlabel?.text = team.name string } var removed = false (index, value) in enumerate(self.teamselected) { if (value.id == team.id) { cell.accessoryview = cell.accessorycheck removed = true } } if (!removed) { cell.accessoryview = cell.accessoryuncheck } cell.selectionstyle = uitableviewcellselectionstyle.none return cell }
Comments
Post a Comment