objective c - Searching for a dictionary value in an array of dictionaries -
objective c - Searching for a dictionary value in an array of dictionaries -
i'm trying search array of dictionaries. each dictionary has different keys , values name, age , joindate.
i searching based on tutorial next code:
- (void) searchtableview { nsstring *searchtext = searchbar.text; nsmutablearray *searcharray = [[nsmutablearray alloc] init]; (nsdictionary *dictionary in listofitems) { nsarray *array = [dictionary valueforkey:@"name"]; [searcharray addobjectsfromarray:array]; } (nsstring *stemp in searcharray) { nsrange titleresultsrange = [stemp rangeofstring:searchtext options:nscaseinsensitivesearch]; if (titleresultsrange.length != 0) [copylistofitems addobject:stemp]; } [searcharray release]; searcharray = nil; }
the searching goes , info displayed correctly.
the problem when take 1 of results point wrong location.
here how selected row directed detail view:
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { nsstring *selectedname = nil; if(searching) selectedname = [copylistofitems objectatindex:indexpath.row]; else { selectedapp = [[dao libraryitematindex:indexpath.row] valueforkey:@"name"]; } [self.tableview deselectrowatindexpath:[self.tableview indexpathforselectedrow] animated:yes]; detailviewcontroller *controller = [[detailviewcontroller alloc] initwithappdata:[dao libraryitematindex:indexpath.row] nibname:@"detailviewcontroller" bundle:[nsbundle mainbundle]]; controller.selectedname = selectedname; [self.navigationcontroller pushviewcontroller:controller animated:yes]; [controller release]; [detailviewcontroller release];
}
i need way point right location.
if find index of name i'm looking in main array great.
it much appreciated if u help me this.
you can subclass uitableviewcell , add together fields storing did find whatever displayed in cell (like in dictionary , @ position in array). you'll able when cell clicked.
objective-c
Comments
Post a Comment