2010-04-11 92 views
1

我使用UIPickerViewController拍照。它工作80%,但看似随意,它没有拍照。在追踪代码时,我发现它偶尔会去iPhone:UIImagePickerController随机拍照失败

-PinRecordNewTableViewController:viewDidUnload. 

这是失败的原因,因为它将nil设置为所有ivars。

@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]; 

    } 

我做错了什么?我错过了什么导致它“随机”行为?

在此先感谢您的帮助。

+0

这个问题很可能在'imagePickerController:didFinishPickingMediaWithInfo:'或'imagePickerControllerDidCancel:'你应该将该代码发布到你的答案。另外,更多的描述会有所帮助。当你无法拍照时,你看到了什么行为?它是否像它一样行动,但你没有存储图像?选取器控制器视图不显示?细节很重要。 – TechZen 2010-04-11 21:27:20

回答

0

如果它调用viewDidUnload,那么很可能是您的应用程序内存不足。这可能是一个问题,或者只是在手机中编辑大图片的结果。

+0

我只是拍一张普通的照片。如果我设置“picker.allowsEditing = NO;”会有帮助吗? ? – pion 2010-04-11 21:12:02

+0

是的,几乎可以肯定,除非你在其他地方有一个不好的泄漏。 – 2010-04-11 21:29:14

+0

我刚刚运行XCode - >运行 - >运行性能工具 - >泄漏。它说我在下面的代码中具体泄漏了“UIImagePickerController * picker = [[UIImagePickerController alloc] init];”。 但我不明白为什么。 我做错了什么? (void)picturePicker:(UIImagePickerControllerSourceType)theSource UIImagePickerController * picker = [[UIImagePickerController alloc] init];(UIImagePickerControllerSourceType) \t picker.delegate = self; \t picker.sourceType = theSource; \t picker.allowsEditing = NO; \t \t [self presentModalViewController:picker animated:YES]; \t \t [picker release]; } – pion 2010-04-11 21:34:17

0

如果您尝试拍摄多张照片,请将当前照片保存到应用程序的“文档”区域。它释放了内存。这样可以避免内存警告。

如果正在调用ViewDidUnload,则可能会考虑将应用程序的相关状态保存在didReceiveMemoryWarning中,并将其恢复到viewDidLoad中。这是使用NSUserDefaults类