如果我的应用程序停止运行或设备已关闭,我的文本字段和从图像选择器中选择的图像全部重置为空白,我该如何保留这些信息?
我使用了单例(在其他成员的帮助下),我可以保留我的图像……直到应用程序被杀死或设备被关闭。然后就没了。
.m
- (void)viewDidLoad
{
singletonObj = [Singleton sharedSingletonController];
imageView.image = singletonObj.imagePicked;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setImageView:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#pragma mark - Action
- (IBAction)done:(id)sender
{
[self.delegate flipsideViewControllerDidFinish:self];
}
- (IBAction)btn:(id)sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
NSData *dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
UIImage *img = [[UIImage alloc] initWithData:dataImage];
singletonObj.imagePicked = img;
imageView.image = img;
[picker dismissModalViewControllerAnimated:YES];
}
@end