Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSFetchedResultsController不';如果提供了委托,则无法获取 Edit*这样看来我使用它的目的是错误的,在初始获取时将永远不会调用委托。我想使用它来批处理获取,因为即使数据的实际获取速度很快,但后处理速度却不快。我只需要卸载到后台进程,而不是编辑*_Ios_Core Data_Nsfetchedresultscontroller - Fatal编程技术网

Ios NSFetchedResultsController不';如果提供了委托,则无法获取 Edit*这样看来我使用它的目的是错误的,在初始获取时将永远不会调用委托。我想使用它来批处理获取,因为即使数据的实际获取速度很快,但后处理速度却不快。我只需要卸载到后台进程,而不是编辑*

Ios NSFetchedResultsController不';如果提供了委托,则无法获取 Edit*这样看来我使用它的目的是错误的,在初始获取时将永远不会调用委托。我想使用它来批处理获取,因为即使数据的实际获取速度很快,但后处理速度却不快。我只需要卸载到后台进程,而不是编辑*,ios,core-data,nsfetchedresultscontroller,Ios,Core Data,Nsfetchedresultscontroller,我在UIViewController的ViewDidLoad方法中创建NSFetchedResultsController,并将委托设置为self: self.resultsController = [[[NSFetchedResultsController alloc] initWithFetchRequest:self.fetchRequest managedObjectContext:[AppDelegate singleton].managedObjectContext sectionN

我在UIViewController的ViewDidLoad方法中创建NSFetchedResultsController,并将委托设置为self:

self.resultsController = [[[NSFetchedResultsController alloc] initWithFetchRequest:self.fetchRequest managedObjectContext:[AppDelegate singleton].managedObjectContext sectionNameKeyPath:nil cacheName:nil] autorelease];
self.resultsController.delegate = self;
然后,当点击ViewController时,如果需要,我将执行提取:

int indexPathCount = self.indexPaths.count;
int objectCount = self.resultsController.fetchedObjects.count;
if (indexPathCount && objectCount)
{
     [self.tableView beginUpdates];
     [self.tableView insertRowsAtIndexPaths:self.indexPaths withRowAnimation:UITableViewRowAnimationFade];
     [self.tableView endUpdates];
}
else
{
     NSError* error;
     BOOL success = [self.resultsController performFetch:&error];
     if (!success)
     {
          UIAlertView* alert = [[[UIAlertView alloc] initWithTitle:@"ERROR" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
          [alert show];
     }
}
上面的代码不会获取任何对象,也不会调用委托方法。如果我注释掉上面指定UIViewController作为委托的代码行,那么在第二次运行被点击的代码期间,objectCount将包含一个正确的值

  • 编辑*上面的代码现在将实际获取对象。在代码的第二次运行中,objectCount现在与预期的一样,但仍然没有调用委托方法。现在我的假设是,我在内存管理方面做了一些不好的事情,但我所有的保留计数似乎都是正确的。*编辑*
下面是委托方法的实现,但我已经对它们的正确性检查了十几次:

- (void)controllerWillChangeContent:(NSFetchedResultsController*)controller
{
     [self.tableView beginUpdates];
}

- (void)controller:(NSFetchedResultsController*)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath*)newIndexPath
{
     switch(type)
     {
          case NSFetchedResultsChangeInsert:
          {
               NSIndexPath* tableIndexPath = [NSIndexPath indexPathForRow:newIndexPath.row inSection:self.section];
               [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:tableIndexPath] withRowAnimation:UITableViewRowAnimationFade];
               [self.indexPaths addObject:tableIndexPath];
          } break;
     }
}

- (void)controllerDidChangeContent:(NSFetchedResultsController*)controller
{
     [self.tableView endUpdates];
}

关于NSFetchedResultsController在提供代理时为何不工作,您有什么想法吗?

信息不足。嗯,不是正确的信息。既然你没有发帖,我只能假设

首先,获取请求是什么样子的?它是否正确指定要获取的对象?它是否有排序描述符(FRC获取请求的要求)


通常,在视图控制器加载时启动请求。。。手动调用插入数据(如代码显示)是非常不寻常的,

您是否尝试不为self.resultcontroller分配自动删除的NSFetchedResultsController?为什么?在我调用perform fetch的tap方法中,NSResultsController存在,并且在第二次运行该方法时,该方法将实际包含FetchedObject。我现在无法启动委托,因此行将被添加到UITableView。您是否至少尝试过不自动释放它?我不需要立即加载数据。它通过用户交互加载。并且fetch请求可以工作。我可以使用managedObjectContext触发请求,并将对象很好地返回。NSFetchedResultsController现在也在获取对象,只是没有触发委托方法。因此,我似乎是出于错误的目的使用它,需要在加载中执行获取。我实际上不需要担心数据的更改,我只是将其用于批处理,这不是它的目的。如果您只是想获取数据,请在MOC上使用executeFetchRequest。FRC用于监视数据库的任何更改。是的,我最初是这样做的,后来被切换,因为我认为我可以得到一些批处理改进。我现在换回去了。谢谢