I have a UI that displays data from a user table like FirstName, LastName, Email,etc. Now i want to create a search bar along with scope buttons that filters data depending on the scope button clicked. I have 2 scope buttons, FirstName and LastName. By default FirstName button is selected. Below is how I add my data to a mutablearray,
userData = [[NSMutableArray alloc] init];
for (NSDictionary *tmpDic in response) {
[userData addObject: [NSString stringWithFormat: @"%@ %@",
[tmpDic valueForKey: @"FirstName"],[tmpDic valueForKey: @"LastName"]]];
}
My search code,
- (void) searchTableView {
NSString *searchText = theSearchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSString *sTemp in userData)
{
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[copyuserData addObject:sTemp];
}
NSLog(@"Copied data is:%@", copyuserData);
[searchArray release];
searchArray = nil;
}
The above code works well for searching the userData array, but i am not sure how will i change the code so that depending on FirstName, LastName scope buttons it will display the result. how i will hook up the buttons to the search bar so that it only display result depending on what scope bar button is clicked. Thanks in advance..