我在我的应用中有一个UISearchBar控制器。它目前搜索的是在线数据库,但我要改为搜索Core Data数据库。它目前使用这段代码:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if (self.billingSearchBar == searchBar) {
[self.billingSearchController filterResultsUsingString:searchText];
}
}
- (void)filterResultsUsingString:(NSString *)filterString
{
self.billingSearchText = filterString;
NSArray *billing_codes = [self billingSearch:self.billingSearchText searchType:self.billingSearchCategory];
self.displayedBillingSearch = billing_codes;
self.billingSearch = billing_codes;
[self.tableView reloadData];
}
-(NSMutableArray*)billingSearch:(NSString*)searchString searchType:(NSString*)searchType
{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/server/20111115/60b88126/billing_search/", [self getHost]]];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setPostValue:searchString forKey:@"query"];
[request setPostValue:searchType forKey:@"category"];
[request startSynchronous];
NSError *error = [request error];
NSString *responseString;
if (!error) {
responseString = [request responseString];
}
NSMutableArray *search_results = [[NSMutableArray alloc] init];
NSDictionary *responseDictionary = [responseString JSONValue];
for (id key in [responseDictionary valueForKey:@"search_results"]) {
[search_results addObject:key];
}
return search_results;
}
我已经在Core Data中设置好了数据库,现在只需要将搜索/NSFetchedResults控制器与之连接起来。有什么简单的方法可以做到吗?
NSFetchRequest
и°“иҜҚ并жү§иЎҢж–°зҡ„иҺ·еҸ–жӣҙе®№жҳ“гҖҒжӣҙз®ҖжҙҒгҖӮжӢҘжңүеӨҡдёӘNSFetchedResultsController
жІЎжңүж„Ҹд№үгҖӮ - gschandler