开发者

Objective C: Filtering Core Data Information based on Set of Annotations visible in current MapRect

I have around 1000+ core data objects for my application. The application consist of a mapView and a tableView.

I am interested in displaying only the annotations that are appearing in the current mapRect. Hence I am using the method

NSSet *nearbySet = [self.mapView annotationsInMapRect:self.mapView.visibleMapRect];

The above method will return me a set of annotations available in the current mapView.

Now I only want to display the information based on the annotations returned from the above method in the table view (CoreData Table). How can I query core data for this? Can I use the predicate method with the NSFetchResultController? Any advice on this will be greatly appreicated!

Zhen Hoe

EDIT (10.05.2011): My location data model is as such:

@dynamic uniqueID;
@dynamic name;
@dynamic address;
@dynamic longitude;
@dynamic latitude;

I have implemented the CoreDataTableViewController as shown below:

- (NSFetchedResultsController *)fetchedResultsControllerForTableView:(UITableView *)tableView
{
    if (tableView == self.tableView) 
    {
        if (self.fetchedResultsController.fetchRequest.predicate != normalPredicate) 
        {
            [NSFetchedResultsController deleteCacheWithName:self.fetchedResultsController.cacheName];
            self.fetchedResultsController.fetchRequest.pre开发者_开发知识库dicate = normalPredicate;
            [self performFetchForTableView:tableView];
        }
        [currentSearchText release];
        currentSearchText = nil;
    } 
}

I was thinking of modifying the line 'self.fetchedResultsController.fetchRequest.predicate = normalPredicate" to restrict the fetch to only the objects found in my nearbySet. Is this a good place to do it? Also if you can give me some tips on how to write the predicate part, that will be great!

Thanks

Zhen Hoe

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜