gpt4 book ai didi

iphone - NSFetchResultsController 委托(delegate)没有被调用

转载 作者:行者123 更新时间:2023-12-01 19:16:21 25 4
gpt4 key购买 nike

我有以下代码:

- (NSFetchedResultsController *)fetchedResultsController {
// Set up the fetched results controller if needed.
if (fetchedResultsController == nil) {

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"DiskStory" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

fetchRequest.predicate = [NSPredicate predicateWithFormat:@"isRemoved == %@", [NSNumber numberWithBool:NO]];

// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"created" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

[fetchRequest setSortDescriptors:sortDescriptors];

// Set limit
[fetchRequest setFetchBatchSize:25];
// Set batch size
[fetchRequest setFetchLimit:50];


NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:kSavedStoryCache];
aFetchedResultsController.delegate = self;
fetchedResultsController = aFetchedResultsController;
}
return fetchedResultsController;
}

在我看来DidLoad 我有:
 NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}

我想知道为什么我的:
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {

}

代表,不是叫吗?我在里面放了一个断点。任何的想法?

最佳答案

我之前也遇到过这个问题,调用时没有调用performFetch第一次,但仅限于 fetchedResultsController 中的数据实际上是改变了。例如,当您从此获取结果中的上下文中删除对象时,将调用委托(delegate)。

关于iphone - NSFetchResultsController 委托(delegate)没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13020523/

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