简体   繁体   English

iPhone:UIImagePickerController随机无法拍照

[英]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.

相关问题 使用UIImagepickerController cameraoverlayview拍照? - using UIImagepickerController cameraoverlayview to take picture? iPhone-UIImagePickerController进行屏幕截图吗? - iPhone - UIImagePickerController take screen shots? ARToolkit,UIImagePickerController和cameraOverlayView:如何拍照? - ARToolkit, UIImagePickerController & cameraOverlayView: How to take a picture? iPhone SDK - 如何在UIImagePickerController中禁用图片预览? - iPhone SDK - How to disable the picture preview in UIImagePickerController? UIImagePickerController中的takePicture方法不会每次都立即拍照 - takePicture method in UIImagePickerController does not take a picture instantly every time 我可以使用UIImagePickerController拍摄多张图片吗? - Can I take more than one picture with the UIImagePickerController? 允许用户在UIImagePickerController中以纵向视图尺寸拍摄图片 - Allow user to take Picture in portrait view dimensions in UIImagePickerController 通过使用UIImagePickerController,我可以裁剪图片并将其保存在iPhone目录中吗? - by using UIImagePickerController, i can crop the picture and also save it in iphone directory? iPhone拍摄UIImagePickerController视图的屏幕截图-如果TAB应用程序始终为黑色 - iPhone Take Screenshot of UIImagePickerController View - Always black if TAB app 如何使iPhone应用程序使用UIImagePickerController拍摄好照片? - How to get iPhone app to take good pictures using UIImagePickerController?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM