Iphone 使用NSFetchedResultsController搜索外部数据

Iphone 使用NSFetchedResultsController搜索外部数据,iphone,objective-c,core-data,ios5,nsfetchedresultscontroller,Iphone,Objective C,Core Data,Ios5,Nsfetchedresultscontroller,我有一个使用NSFetchedResultsController自动填充和更新表视图的表。用于填充该表的数据来自外部服务器(XML调用),仅表示服务器上实际数据的子集 问题是:我希望在此表上方有一个搜索栏,但不是搜索应用程序数据(只有一小部分),而是在服务器上搜索,然后使用此表返回结果 NSFetchedResults设计用于只搜索应用程序上的核心数据,而不是远程服务器。如何集成外部服务器搜索并显示这些结果?我不想只为了搜索而转到另一个ViewController。我认为不可能使用NSFetch

我有一个使用NSFetchedResultsController自动填充和更新表视图的表。用于填充该表的数据来自外部服务器(XML调用),仅表示服务器上实际数据的子集

问题是:我希望在此表上方有一个搜索栏,但不是搜索应用程序数据(只有一小部分),而是在服务器上搜索,然后使用此表返回结果


NSFetchedResults设计用于只搜索应用程序上的核心数据,而不是远程服务器。如何集成外部服务器搜索并显示这些结果?我不想只为了搜索而转到另一个ViewController。

我认为不可能使用NSFetchedResultsController进行此操作,因为您没有要关联的NSFetchRequest

但您可以做的是在表视图委托方法中加入一些逻辑,当您进行搜索时,您可以填充一个NSArray并将其作为数据源提供给表,然后您可以重新加载它本身

// call to server
NSArray *remoteDatasource = <<populate from call>>;
AppSearchMode searchMode = AppSearchModeRemote; // this is an enum you could declare in .h
我希望我能说清楚,我以前也做过类似的事情

// table view related
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    switch(searchMode) {
       case AppSearchModeCoreData:
         return [[self fetchedResultsController] sections] count];
       case AppSearchModeRemote:
         return [remoteDatasource count];
    }
}