I have two arrays (first names, Last names) in my TableView (cell.textLabel and cell.detailTextLabel)
I want to make a search bar in this TableView.
I have created class with two string.
@interface clientContent : NSObject { }
@property (nonatomic, strong) NSString *clName;
@property (nonatomic, strong) NSString *clLast;
@end
then I have created array in main class (which have Table view) and added my information
like this
for (int i = 0; i < PQntuples(clientQuery); i++)
{
clientContent *cc = [[clientContent alloc] init];
cc.clName = [[NSString alloc] initWithUTF8String:PQgetvalue(clientQuery, i, 0)];
cc.clLast = [[NSString alloc] initWithUTF8String:PQgetvalue(clientQuery, i, 1)];
[allClients addObject:cc];
}
after this I load it into tableView;
clientContent *cc = [allClients objectAtIndex:indexPath.row];
cell.textLabel.text = cc.clName;
cell.detailTextLabel.text = cc.clLast;
}
Then I use
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
How to make it right? I can’t understand..
You should override searchDisplayController:shouldReloadTableForSearchString: delegate method of UISearchDisplayController and filter datasource array for searchResultsTableView as you want.
You can apply predicate on your array(array of clientContent object) and change dataSource array. Using predicate you can filter your array on both fields(clName & clLast).
You can get help related to predicates from https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSPredicate_Class/Reference/NSPredicate.html