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:

  • Override -didReceiveMemoryWarning to do nothing.
  • Save state in -viewDidDisappear:, which should always be called before the view gets unloaded (unless the view never appeared in the first place).
  • Save state as the user edits it, either by persisting it immediately (if you have no cancel button) or to an property/ivar in the view controller (if you want to only save if the user doesn't click cancel).

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.

Need Your Help

Checkboxes in DataGrid

asp.net vb.net checkbox datagrid

I have a GridView containing a column with checkboxes. The header template has a a checkbox to select all the other checkboxes in the column.

Facebook. Publish text on facebook wall by clicking image

php facebook api session stream

I want to make a facebook app, when user click on image auto publish some text on user's wall.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.