我正在展示UIImagePicker
我的一个UIViewController
,在我的UIViewController
我有几个UITextField
。
现在用户已经在其中填写了一些值,UITextField
然后他从 中选择了一张图像UIImagePicker
,之后它收到了内存警告,并再次调用 viewDidLoad,但是用户在 中输入的所有数据UITextField
都丢失了。我该如何处理?
代码:
- (void) showImageSelector: (UITapGestureRecognizer *) tapGestureRecognizer
{
UIActionSheet *actionSheet;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
actionSheet = [[UIActionSheet alloc] initWithTitle:[PNRConstants kChoosePhoto] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:[PNRConstants kPhotoLibrary], [PNRConstants kTakeAPicture], nil];
}
else{
actionSheet = [[UIActionSheet alloc] initWithTitle:[PNRConstants kChoosePhoto] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:[PNRConstants kPhotoLibrary], nil];
}
[actionSheet showInView:self.view.window];
}
#pragma -
#pragma UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != actionSheet.cancelButtonIndex) {
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.delegate = self;
controller.allowsEditing = YES;
if (buttonIndex == 0) {
// Photo Library
controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
else {
// Camera
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentViewController:controller animated:YES completion:nil];
}
}