【问题标题】:Error: "keypath objectID not found in entity"错误:“在实体中找不到键路径 objectID”
【发布时间】:2012-03-30 10:50:27
【问题描述】:

我收到此错误: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath objectID not found in entity <NSSQLEntity Pair id=2>'

当我使用“objectId”作为 NSFetchedResultsController 的搜索描述符和 sectionNameKeyPath 时。

我希望每个对象产生一个新部分。

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"objectID" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];

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

有什么建议吗?

提前致谢。

【问题讨论】:

    标签: iphone uitableview nsfetchedresultscontroller


    【解决方案1】:

    可能是因为 objectId 和 objectID 是不同的字符串。检查一下。

    【讨论】:

      【解决方案2】:

      我遇到了同样的错误。原因是我创建了临时的 NSManagedObjectContext 实例而不保留它。简单地创建对象并将它的引用分配给一个变量就解决了我的问题。

      【讨论】:

        猜你喜欢
        • 2011-01-30
        • 1970-01-01
        • 2021-10-19
        • 2015-08-18
        • 2014-06-07
        • 2011-04-12
        • 2013-04-05
        • 2017-02-11
        • 2010-10-18
        相关资源
        最近更新 更多