iphone - [[NSFetchedResultsController alloc] initWithFetchRequest上的SIGBART

标签 iphone ios nsfetchedresultscontroller

我在代码中的这一行收到sigbart错误:

NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"ViewTwo"];

这是方法:
- (NSFetchedResultsController *)fetchedResultsController
{
if (__fetchedResultsController != nil) {
    return __fetchedResultsController;
}

// Set up the fetched results controller.
// Create the fetch request for the entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyData" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];

// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"ViewTwo"];

aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;

NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
    /*
     Replace this implementation with code to handle the error appropriately.

     abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
     */
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

return __fetchedResultsController;
}

但这是一个奇怪的错误,因为在控制台中没有给我任何解释,所以我无法理解自己在做什么错。

最佳答案

NSFetchedResultsController需要排序描述符和托管对象上下文。您没有提供排序描述符,因此必须给它。

关于iphone - [[NSFetchedResultsController alloc] initWithFetchRequest上的SIGBART,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11302644/

相关文章:

javascript - 使用 iPhone 时用于加载跨站点 HTML 的 iframe 替代方案?

ios - 防止键盘阻塞单元格

ios - 向 NSFetchedResultsController 管理的 UITableView 添加额外的行

ios - NSFetchedResultsController 未按预期获取

ios - NSFetchedResultsController 与 NSPredicate

iphone - xcode构建错误

iphone - 是否可以在 iPhone 上发送 "silent"推送通知(不向用户发出任何警报)?

ios - 如何在新的 UIViewController 中打开我在 UIWebView 中的 mp3 链接?

ios - ScrollView 、缩放和缩放原点混淆

ios - Xcode 依赖错误