我有这个代码在我的iPhone应用程序中拍照:
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else{
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentModalViewController:picker animated:YES];
}
然后我有另外一个控制器来管理拍摄的照片:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
[picker.parentViewController dismissModalViewControllerAnimated:YES];
imageTaken.image = image;
NSLog(@"saved!");
}
我尝试在我的iPhone 4(iOS 4.something)上启动应用程序,在拍完照片并点击“使用”后,我得到一个白色屏幕。当直接在另一部手机上测试应用程序时,直接从XCode(这次是iOS 5)启动以检查日志,我点击“使用”但是没有任何反应,并且正确打印了日志。
你知道发生了什么吗?我认为图片的屏幕没有关闭,但我打电话给dismissModalViewController ....
谢谢,
Masiar
答案 0 :(得分:1)
你应该以这种方式解雇模态视图控制器,
[self dismissModalViewControllerAnimated:YES];
最好使用imagePickerController:didFinishPickingMediaWithInfo:
,因为其他方法已被弃用。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissModalViewControllerAnimated:YES];
imageTaken.image = (UIImage *)[info objectForKey: UIImagePickerControllerEditedImage];
}