Monday, 15 August 2011

ios - Search function in iphone? -



ios - Search function in iphone? -

my array

{ "samsung tab", "samsung note", "samsung galaxy", "samsung galaxy pro", "nokia lumia", "nokia 5130", "sony xperia" }

some thing that. have text box type galaxy , click button. want show samsung galaxy , samsung galaxy pro in next list view. can help me?.

take 2 nsmutablearray , add 1 array array in viewdidload method such like,

self.listoftemarray = [[nsmutablearray alloc] init]; // array no - 1 self.itemofmainarray = [[nsmutablearray alloc] initwithobjects:@"yorarraylist", nil]; // array no - 2 [self.listoftemarray addobjectsfromarray:self.itemofmainarray]; // add together 2array 1 array

and write next delegate method of uisearchbar

- (bool) textfielddidchange:(uitextfield *)textfield { nsstring *name = @""; nsstring *firstletter = @""; if (self.listoftemarray.count > 0) [self.listoftemarray removeallobjects]; if ([searchtext length] > 0) { (int = 0; < [self.itemofmainarray count] ; = i+1) { name = [self.itemofmainarray objectatindex:i]; if (name.length >= searchtext.length) { firstletter = [name substringwithrange:nsmakerange(0, [searchtext length])]; //nslog(@"%@",firstletter); if( [firstletter caseinsensitivecompare:searchtext] == nsorderedsame ) { // strings equal except perchance case [self.listoftemarray addobject: [self.itemofmainarray objectatindex:i]]; nslog(@"=========> %@",self.listoftemarray); } } } } else { [self.listoftemarray addobjectsfromarray:self.itemofmainarray ]; } [self.tblview reloaddata]; }

}

output show in consol.

this code might helpful you...thanks :)

iphone ios

No comments:

Post a Comment