I have a form with two UITextFields and a button. The user enters values into the two fields and then clicks the button. This displays the UIImagePickerController so he/she can take a picture. After clicking the “Use” button on the picture preview, the UIImagePickerController is dismissed, but any text that had been entered in the two UITextFields is gone. This only happens on the IPhone (not the IPad) and only happens when the user uses the camera as opposed to choosing a picture from the camera roll. Here is the code.
-(IBAction)btnTakePic {
if([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects: (NSString *) kUTTypeImage, nil];
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
imagePicker.allowsEditing = NO;
[self presentModalViewController: imagePicker animated:YES];
[imagePicker release];
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
}
I have stepped through the debugger and upon entering the picker DidFinishPickingWithMediaInfo, the text fields are already blank, so the problem doesn’t appear to be occurring in there. The IPad is running 4.3.3, the IPhone is 4.2.1, and the app is being developed in XCode 4 with 4.3 as the base sdk and 4.2 as the deployment target. Any help is appreciated.
I would suspect you are getting a memory warning (common when using the camera) and the view is unloading, when the view reloads (after returning from the image picker) the view is in its default state, boxes empty.
You need to store the values of the boxes when they are entered (in variables), then in viewDidLoad check if you have values, if you do set the text fields text property to the desired values.
Check the console, you will most likely have Memory Warning Level 1 (or maybe 2)