Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have had the same problem. When the imagePicker is opened there is a memory warning and the ViewController is discarted. So you lose anything in your ViewController. For example if you have any UITextField you will also lose its content. So you need to store the state of your ViewController somewhere else when the method didReceiveMemoryWarning is called. You can store values in the NSUserDefaults, in files, in your AppDelegate,...</p> <p>Saving an image in a file is a <a href="https://stackoverflow.com/questions/1655057/fastest-way-to-write-a-large-file-on-the-iphone">big time consumption task</a>. So my solution has been to save the image in the AppDelegate, in memory. I've created an UIImage *image variable inside the delegate. Then when the imagePicker finishes I store the image in that field:</p> <pre><code>- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage]; imageView.image = editedImage; // it works if no memory warning is received YourAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; delegate.image = editedImage; } </code></pre> <p>Then if the ViewController has been discarted it's needed to read the stored image from the AppDelegate in the viewDidLoad method.</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // if you have used NSUserDefalts to store the state of your UITextFields // when the didReceiveMemoryWarning was called NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *name = [defaults objectForKey:@"name"]; if (name != nil) { textFieldName.text = name; } // show the saved image YourAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; UIImage *image = delegate.image; if (image != nil) { imageView.image = image; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload