objective c - IOS: getting the value of "id" along with an item is selected through table view -
in project response data in form of
{ "procedures": [5950] 0: { "procedures": { "id": "1" "procedure_name": "3d render w/o postprocess" "procedure_code": "76376" } } 1: { "procedures": { "id": "2" "procedure_name": "3d rendering w/postprocess" "procedure_code": "76377" }
there 5950 elements in data array. create separate arrays "id" , "procedure_name" , show data in uitableview
displays correct data id. applied search functionality filter data difficult find element in 5950 elements scrolling. search function works when select uitableviewcell
of filtered result doesn't provide actual id of element whereas returns current indexpath
value of uitableview
. searching put following code
- (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string { temparray = [nsarray arraywitharray:dataarray]; nsstring *stringtosearch = textfield.text; nspredicate *predicate = [nspredicate predicatewithformat:@"self beginswith[c] %@",stringtosearch]; // if need case sensitive search avoid '[c]' in predicate nsarray *tempresults = [dataarray filteredarrayusingpredicate:predicate]; if (tempresults.count > 0) { temparray = [nsarray arraywitharray:tempresults]; } [searchdiagtable reloaddata]; return yes; }
in didselectrow method apply following code
if (tableview == searchdiagtable) { uitableviewcell *selectedcell = [searchdiagtable cellforrowatindexpath:indexpath]; nslog(@"%@", selectedcell.textlabel.text); searchdiag. text = selectedcell.textlabel.text; searchresultid = [iddict objectatindex:indexpath.row]; // iddict array store values of "id" dictionary. [searchdiagtable deselectrowatindexpath:indexpath animated:yes]; searchdiagtable.hidden = yes; }
checking on question can issue must using wrong array iddict
search looks me should temparray
Comments
Post a Comment