[英]iPhone: UIImagePickerController Randomly Fails to Take Picture
I use a UIPickerViewController to take picture. 我使用UIPickerViewController拍照。 It works 80% but seemingly at random it fails to take a picture.
它可以工作80%,但看似随机地无法拍照。 In tracing the code I found out that it occasionally goes to
在跟踪代码时,我发现它偶尔会
-PinRecordNewTableViewController:viewDidUnload.
That is where it fails because it set nil to all ivars. 那是失败的地方,因为它将所有ivars设为nil。
@interface PinRecordNewTableViewController : UITableViewController {
}
...
@implementation PinRecordNewTableViewController
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
...
PinRecordNewPicture *pinRecordNewPicture = [[PinRecordNewPicture alloc] initWithNibName:@"PinRecordNewPicture" bundle:nil];
pinRecordNewPicture.delegate = self;
[self.navigationController pushViewController:pinRecordNewPicture animated:YES];
[pinRecordNewPicture release];
...
}
@interface PinRecordNewPicture : UIViewController
...
@implementation PinRecordNewPicture
...
- (void)picturePicker:(UIImagePickerControllerSourceType)theSource {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = theSource;
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (IBAction) takePicture:(id)sender {
UIImagePickerControllerSourceType source = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable:source]) {
[self picturePicker:source];
}
What did I do wrong? 我做错了什么? Did I miss something that causes it to behave "randomly"?
我是否错过了某种使它表现为“随机”行为的东西?
Thanks in advance for your help. 在此先感谢您的帮助。
If it called viewDidUnload
, then it is very likely that your app is running out of memory. 如果调用了
viewDidUnload
,则很可能是您的应用程序内存不足。 This could be a problem, or just the result of editing large images in phone. 这可能是一个问题,或者仅仅是在手机中编辑大图像的结果。
If you're trying to take multiple pictures, save the current one to the Documents area of the app. 如果您要拍摄多张照片,请将当前照片保存到应用程序的“文档”区域。 It frees up the memory.
它释放了内存。 This way, the memory warning can be avoided.
这样,可以避免内存警告。
If ViewDidUnload is being called, you might think about saving the relevant state of the app in didReceiveMemoryWarning and restoring it in viewDidLoad. 如果正在调用ViewDidUnload,您可能会考虑将应用程序的相关状态保存在didReceiveMemoryWarning中,然后将其恢复到viewDidLoad中。 This is done using NSUserDefaults class
这是使用NSUserDefaults类完成的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.