NSPredicate在首次发布时不会执行

时间:2013-04-23 20:44:32

标签: iphone ios core-data restkit nspredicate

我已经获得了很多论坛,但我仍然没有找到答案。

我从某个网址加载数据。我收到的项目包含“删除”属性,我在tableView中显示对象时依赖它。

- (void)loadData
{
    [self showLoadingIndicatorView];
    [[RKObjectManager sharedManager] getObjectsAtPath:@"/api/news/index.json"
                                           parameters:@{@"auth_token" : [BMWConstants authToken]}
                                              success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
                                                  RKLogInfo(@"Load complete: Table should refresh...");
                                                  [super hideLoadingIndicatorView];
                                              } failure:^(RKObjectRequestOperation *operation, NSError *error) {
                                                  RKLogError(@"Load failed with error: %@", error);
                                                  [BMWSuperViewController showGhostAlert:error];
                                                  [super hideLoadingIndicatorView];
                                              }];


}

我使用谓词

创建一个获取结果控制器
(NSFetchedResultsController*)fetchedResultsController
{
if (_fetchedResultsController != nil)
{
return _fetchedResultsController;
}

NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"News"];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"deleted = NO OR deleted = NIL"]];
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"createdAt" ascending:NO];
fetchRequest.sortDescriptors = @[descriptor];
[fetchRequest setFetchBatchSize:10];
NSError *error = nil;

_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:[RKManagedObjectStore defaultStore].mainQueueManagedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
[self.fetchedResultsController setDelegate:self];
BOOL fetchSuccessful = [self.fetchedResultsController performFetch:&error];
if (! fetchSuccessful) {
[BMWCenterViewController showGhostAlert:error];
}
return _fetchedResultsController;
}

[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"deleted = NO OR deleted = NIL"]];

从这里看,谓词设置得很好。

这在第二次启动应用程序时都有效,但在第一次启动时,它只给了我从JSON收到的所有对象,忽略了我的谓词。当我在cellForRowAtIndexPath中记录对象时,属性存在。

你能帮我解决这个问题吗?

0 个答案:

没有答案