0

I have a UISearchBar in my app.and I want the four Scope bars in this UISearchBar that I have given from the XIB file .say one , two , three and four and now Problem is I have four array s which contains separates values for each array ..say array one , array two , array three and array four .

Now I want when I search on pressing scope bar one only array one values should search .. on pressing scope bar two only array twovalues should search and so on ..

Is there any method for scope bar button available to search ?

like If( scope_bar==1){...}else

like If i search for scope barone then it will display only array one. is there any method available ..I searched on the apple documentation but could not get

user2519391
  • 41
  • 1
  • 8

1 Answers1

0

You should read some tutorials about NSDictionary . i have implemented this search on book search app where titles and authors were searched both at same time.

// for each book

NSDictionary * book = NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
title, @"TITLE", author, @"AUTHOR", nil];
[dataSource addObject:book];

after that in search method you can make changes according to your own ease

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{

[tableData removeAllObjects];

if(searchText != nil && ![searchText isEqualToString:@""]){

    for(NSDictionary * book in dataSource){
        NSString * title = [book objectForKey:@"TITLE"];
        NSString * author = [book objectForKey:@"AUTHOR"];

        NSRange titleRange = [[title lowercaseString] rangeOfString:[searchText lowercaseString]];
        NSRange authorRange = [[author lowercaseString] rangeOfString:[searchText lowercaseString]];

        if(titleRange.location != NSNotFound || authorRange.location != NSNotFound)
            [tableData addObject:book];
        }

}

[tableView reloadData];
}
iAhmed
  • 6,556
  • 2
  • 25
  • 31