开发者

NSManagedObject How To Reload

开发者 https://www.devze.com 2023-01-01 19:58 出处:网络
I have a view that consists of a table of existing objects and an Add button, which allows the user to create a new object. When the user presses Add, the object is created in the list view controll

I have a view that consists of a table of existing objects and an Add button, which allows the user to create a new object. When the user presses Add, the object is created in the list view controller, so that the object will be part of that managed object context (via the NSEntityDescription insertNewObjectForEntityForName: method).

The Add view has a property for the managed object. In the list view controller, I create an Add view controller, set the property to the managed object I created, and then push the Add view on to the navigation stack.

In the Add view, I have two buttons for save and cancel. In the save, I save the managed object and pass the managed object back to the list view controller via a delegate method. If the user cancels, then I delete the object and pass nil back to the list view controller.

The complication I am having in the add view is related to a UIImagePickerController. In the Add view, I have a button which allows the user to take a photo of 开发者_运维百科the object (or use an existing photo from the photo library). However, the process of transferring to the UIImagePickerController and having the user use the camera, is resulting in a didReceiveMemoryWarning in the add view controller.

Further, the view was unloaded, which also caused my NSManagedObject to get clobbered. My question is, how to you go about reloading the NSManagedObject in the case where it was released because of the low memory situation?


Just a suggestion, but how about waiting to create the managed object until after the user says they're done editing?

Store all the properties of the "editor" in a dictionary that you persist separately (in case a call comes in during editing, or they want to copy text from another app to paste into the new item in yours), saving each time they edit a field. Then, when the user is done editing, create and save the managed object from the dictionary contents in one go. If they cancel, reset (or drop) the dictionary (and clean up its persistent file). This way you'll have better control in a low memory situation.

0

精彩评论

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