gpt4 book ai didi

ios - 未为 API 监听器调用 NSFetchedResultsController 委托(delegate)

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:52:08 24 4
gpt4 key购买 nike

如果代码将委托(delegate)分配给 NSFetchedResultsController,如下所示:

-(id)initWithFetchedResultsController:(NSFetchedResultsController*)fetchedResultsController
{
self = [super init];
if (self != nil)
{
fetchedResultsController.delegate = self;
_fetchedResultController = fetchedResultsController;
}
return self;
}

NSFetchedResultsControllerDelegate 方法 – controller:didChangeObject:atIndexPath:forChangeType:newIndexPath: 从未在 self 上调用:

-(void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
NSLog(@"Delegate method called"); // Never called
}

predicate没有问题,一个predicate赋值,直接用notifications工作就可以了。

最佳答案

问题是初始的 - (BOOL)performFetch:(NSError **)error 永远不会被调用,因为这个特定的代码只关心结果集的变化,而不是初始集。然而,随之而来的是 Controller 不会注意到它从未有过的数据的变化。如下更改 init 方法可解决问题:

-(id)initWithFetchedResultsController:(NSFetchedResultsController*)fetchedResultsController
{
self = [super init];
if (self != nil)
{
fetchedResultsController.delegate = self;
_fetchedResultController = fetchedResultsController;
[fetchedResultsController performFetch:nil];
}
return self;
}

关于ios - 未为 API 监听器调用 NSFetchedResultsController 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17151160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com