Objective C:根据当前 MapRect 中可见的注释集过滤核心数据信息
我的应用程序有大约 1000 多个核心数据对象。该应用程序由一个mapView 和一个tableView 组成。
我感兴趣的是仅显示当前 mapRect 中出现的注释。因此我使用的方法
NSSet *nearbySet = [self.mapView annotationsInMapRect:self.mapView.visibleMapRect];
上面的方法将返回当前mapView中可用的一组注释。
现在我只想在表视图(CoreData Table)中显示基于上述方法返回的注释的信息。我如何查询核心数据?我可以将谓词方法与 NSFetchResultController 一起使用吗?对此的任何建议将不胜感激!
振和
编辑(10.05.2011): 我的位置数据模型是这样的:
@dynamic uniqueID;
@dynamic name;
@dynamic address;
@dynamic longitude;
@dynamic latitude;
我已经实现了 CoreDataTableViewController,如下所示:
- (NSFetchedResultsController *)fetchedResultsControllerForTableView:(UITableView *)tableView
{
if (tableView == self.tableView)
{
if (self.fetchedResultsController.fetchRequest.predicate != normalPredicate)
{
[NSFetchedResultsController deleteCacheWithName:self.fetchedResultsController.cacheName];
self.fetchedResultsController.fetchRequest.predicate = normalPredicate;
[self performFetchForTableView:tableView];
}
[currentSearchText release];
currentSearchText = nil;
}
}
我正在考虑修改行“self.fetchedResultsController.fetchRequest.predicate = normalPredicate”以将获取限制为仅在我的nearearSet中找到的对象。是这样的吗?一个好地方吗?另外,如果你能给我一些关于如何编写谓词部分的提示,那就太好了,
谢谢珍
锄!
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.predicate = 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论