Reputation: 315
I have a simple database in iPad Application having couple of tables.
The UI displays the table data properly in a master-detail view controller. I want to add a search feature which will search for the given text in all the field/columns of all the tables and give the result.
One crude way is to write a select query using where clause for each columns. But I believe there will be some proper way for that.
Or is it possible to search the UITableView itself and refresh the data ?
Regards,
nirav
Upvotes: 1
Views: 237
Reputation: 596
Code for searching in Table
- (void) searchTableView {
NSString *searchText = searchBar.text;
if([searchText length] == 0)
{
[searchArr addObjectsFromArray:userArr];
}
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (int i=0; i<[userArr count]; i++) {
NSString *sTemp = [[userArr objectAtIndex:i] objectForKey:@"name"];
NSRange titleResultsRange = [[sTemp lowercaseString] rangeOfString:[searchText lowercaseString]];
if(titleResultsRange.location != NSNotFound && titleResultsRange.location == 0)
{
[searchArr addObject:[userArr objectAtIndex:i]];
}
}
searchArray = nil;
}
Upvotes: 1