UIImagePickerController releases my views and controllers
I have 5 tabs in my application, the fifth tab is Settings tab, (UINavigationController inside), one of the options is where user is able to edit personal info and choose a profile picture.
After firing UIImagePickerController (camera mode) and pressing cancel (I'm not even talking about taking a picture) everything is returned to an original state, to the first tab, all views and controllers were released and recreated by iOS. Everything that user has updated in the settings and didn't save is gone.
How is it possible to avoid that?
Note: I'm using singleton instance of UIImagePickerController, no leaks found with Instruments. "Received memory warning. Level=1" appears constantly when I fire the picker.
You'll be a life saver - thanks!
-- EDIT --
Found it:
I was using a custom tab bar (UIView), so in the settings I was presenting the UIImagePickerController modal from that custom tab bar controller (which is main in the app) (otherwise the picker would go underneath it).
I rebuilt the tab bar so now the custom view just a subview on a standard UITabBar and now I'm calling [self presentModalViewController:imagePickerController animated:YES]; in my app settings and it works just fine.
So, the conclusion is that image picker acts weirdly when you're presenting it from another controller and not from "self".
Sounds like you're not handling memory warnings properly. In the simulator, you can select "Simulate Memory Warning" to simulate what happens.
The long story is that -[UIViewController didReceiveMemoryWarning]
releases its view if the view does not have a superview. There are three easy ways to handle this:
-didReceiveMemoryWarning
to do nothing. -viewDidDisappear:
, which should always be called before the view gets unloaded (unless the view never appeared in the first place). You might also want to think about what happens if your app is backgrounded and killed...
What you could do is make variables for all the fields, and write the contents of the user fields to those variables, and then when the image is taken, or canceled, write all those fields back and release the variables. Basically you temporarily save all the fields, then restore them.
链接地址: http://www.djcxy.com/p/68374.html上一篇: iOS:在拍摄照片后如何在视图之间切换?