使用fetchedResultsContainer在核心数据中出现严重的应用程序错误 [英] Serious Application Error in Core Data with fetchedResultsContainer

查看:138
本文介绍了使用fetchedResultsContainer在核心数据中出现严重的应用程序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试添加记录时出现以下错误:

I get the following error when trying to add a record:


严重的应用程序错误。异常
在Core Data更改
处理期间被捕获。这通常是
NSManagedObjectContextObjectsDidChangeNotification的观察器中的
错误。
索引0对于userInfo无效
(null)

Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. The index 0 is invalid with userInfo (null)

就是这样。我把断点放入我实现的所有fetchedResultsContainer委托方法中,但没有任何中断。

And that's it. I put breakpoints into all the fetchedResultsContainer delegate methods I have implemented, but nothing breaks.

我跟踪到:

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

sectionNameKeyPath是问题。 titleFirstLetter是一个瞬态属性,我在我的NSManagedObject子类中创建了一个getter。

"sectionNameKeyPath" is the problem. "titleFirstLetter" is a transient property that I created a getter for in my NSManagedObject subclass.

这是getter:

-(NSString *)titleFirstLetter
{
  [self willAccessValueForKey:@"titleFirstLetter"];
  NSString *aString = [[self valueForKey:@"title"] uppercaseString];

  NSString *stringToReturn = [aString substringWithRange:[aString rangeOfComposedCharacterSequenceAtIndex:0]];

  [self didAccessValueForKey:@"titleFirstLetter"];
  return stringToReturn;
}



当我将sectionNameKeyPath更改为nil时,它工作,但显然不是什么我想要。它也工作,当我有一个标题已经填充我的模型,所以titleFirstLetter不返回nil,虽然这似乎不是很严重的问题。

When I change the sectionNameKeyPath to nil, it works, but is obviously not what I want. It also works when I have a title already filled in for my model, so that titleFirstLetter doesn't return nil, though that doesn't seem to be quite the problem. If I make the string something arbitrary if it's nil, it still crashes.

任何想法,这里有什么?

Any idea what's up here?

UPDATE:
如果我使用sectionNameKeyPath中的标题而不是transient属性,它不会崩溃,但显然会将每个项目放在其自己的部分。因此它与某种方式相关的瞬态属性...

UPDATE: If I use the title in the sectionNameKeyPath instead of the transient property, it doesn't crash, but obviously puts every item in its own section. So it's somehow related to the transient property...

UPDATE2:
一些初步的黑客使用一个持久性属性而不是瞬态,没有其他的变化,似乎工作很好,所以这看起来是一个错误。我有一个错误报告打开:#8553064

UPDATE2: Some preliminary hacking with using a persistent property instead of transient, and no other changes, seems to work just fine, so this looks to be a bug. I have a bug report open: #8553064

UPDATE3:
好​​吧,使用持久属性没有什么区别。

UPDATE3: Well, scratch that. Using a persistent attribute didn't make any difference. I am somewhat at whits end now.

谢谢!

推荐答案

嗯,这可能是部分(或完全)用户错误。问题是,在添加一个新项目的视图中,我在 viewWillAppear [self.tableView reloadData] c $ c>方法。

Well, this is probably partly (or fully) user error. The problem was that, in the view in which I add a new item, I had put [self.tableView reloadData] inside the viewWillAppear method. Commenting that out did not updated the table cells, but prevented the crash.

然后我再次发送 reloadRowsAtIndexPaths:withRowAnimation:到表视图手动重新加载需要它的几个单元格。

I then went ahead and sent reloadRowsAtIndexPaths:withRowAnimation: to the table view to manually reload the few cells that needed it.

我很高兴终于结束了!

这篇关于使用fetchedResultsContainer在核心数据中出现严重的应用程序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆