Mulitiple Search in the search feild of a table view in objective c -


the requirement if ‘city” has been selected key in search field if user enters ‘brazil,austria’ , rows containing brazil or austria or both should shown in table.

any in regard helpful.i new cocoa

steps follow:

  1. find how cities there in search using regex. (by use of ,(comma))
  2. use predicate find cells contain city name.
  3. update table view cells result of predicate.

edit:

  1. create array of cities name

nsarray *cities = [searchstring componentsseparatedbystring:@","];

  1. create set of unique results

    nsmutableset *searchresultsset = [nsmutableset new]; for(int i=0;i<[cities count];i++) { nspredicate *resultpredicate = [nspredicate predicatewithformat:@"name contains[c] %@", [cities objectatindex:i]];     nsarray *searchresults = [recipes filteredsetusingpredicate:resultpredicate]; [searchresultsset addobjectsfromarray:searchresults]; }

  2. you have final result in set searchresultsset. use show table view cell.

    nsarray *searchresults = [searchresultsset allobjects]; [self.tableview reloaddata];

you can use nscompoundpredicate


Comments