开发者

Disappearing NSManagedObjects

I am working on a document based application.

When opening up a saved file, I load in the NSManagedObjectContext to a view controller. This view controller needs to observe changed on the property "depth" on all objects of a certain type. When the view controller gets the context, it gets all these objects, adds itself as an observer of that value on each, and keeps them in an array to keep track.

Whenever Core Data sends the ContextDidChange notification, I add created objects to this array after observing them. For the deleted objects, I remove the view controller as an observer and remove them from that array.

This works great until I close a document and reopen it. When this happens, all the objects a开发者_StackOverflow中文版re added to this array. The observation works fine. However, the second the first "NSManagedObjectContextObjectsDidChangeNotification" comes in, all of my NSManagedObjects are somehow no longer in the array I set up. On delete, I get a crash telling me I can't remove an observer that's not an observer.

It's very strange.

Why are those NSManagedObjets suddenly gone? I don't release the array or do any funny business with it at all.


When you close a document and reopen it, you are getting a new view controller object.
However, it sounds like the original view controller is still around and still observing:

NSManagedObjectContextObjectsDidChangeNotification.

Check to make sure that when you close your document that the view controller is removing itself as a notification observer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜