0

我已经获取了很多论坛,但仍然没有找到关于我遇到的问题的答案。

我从某个 URL 加载数据。我收到的项目包含我在 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 中记录对象时,该属性存在。

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

4

0 回答 0