Tuesday, 15 April 2014

iphone - Searching a UITableview -



iphone - Searching a UITableview -

i trying search in uitableview. have implemented uisearchdisplaydelegate, uisearchbardelegate method @ right way. how cellforrowatindexpath looks like.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if ( cell == nil ) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } if (tableview == self.searchdisplaycontroller.searchresultstableview){ contact *contact = [self.filteredlistcontent objectatindex:indexpath.row]; nsstring *text = [nsstring stringwithformat:@"%@ %@",contact.name,contact.firstname]; nslog(@"cellforrowatindexpath contact text %@",text); cell.textlabel.text = text; [cell setaccessorytype:uitableviewcellaccessorydisclosureindicator]; }else{ nsstring *alphabet = [firstindex objectatindex:[indexpath section]]; //---get states origin letter--- nspredicate *predicate = [nspredicate predicatewithformat:@"self.name beginswith[c] %@",alphabet]; nsarray *contacts = [listcontent filteredarrayusingpredicate:predicate]; contact *contact = [contacts objectatindex:indexpath.row]; nsstring *text = [nsstring stringwithformat:@"%@ %@",contact.name,contact.firstname]; cell.textlabel.text = text; [cell setaccessorytype:uitableviewcellaccessorydisclosureindicator]; } homecoming cell; }

and filtercontentforsearchtext method

- (void)filtercontentforsearchtext:(nsstring*)searchtext scope:(nsstring*)scope { [self.filteredlistcontent removeallobjects]; // first clear filtered array. (contact *contact in listcontent) { nsstring *searchstring = [nsstring stringwithformat:@"%@ %@",contact.name,contact.firstname]; nsrange range = [searchstring rangeofstring:searchtext options:nscaseinsensitivesearch]; if (range.location != nsnotfound) { [self.filteredlistcontent addobject:contact]; [self.searchdisplaycontroller.searchresultstableview reloaddata]; } } }

the unusual thing is. in cellforrowatindexpath returns me right data. tableview itselfs keeps given me no results label.

any help this?

use array show info in table(showdataarray) use array store input values(dataarray) use showdataarray populate table always in searchfield when charecter range changes phone call method filter info using predicate dataarray save value showdataarray call table reloaddata

happy coding :)

iphone ios objective-c uitableview uisearchbar

No comments:

Post a Comment