我正在使用ipad模拟器测试ipad相机应用程序 我使用下面的代码,更改源类型而不是相机。
-(IBAction)useCamera:(id)sender{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate =(id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>) self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
newMedia = YES;
}
}
当它在模拟器中运行时,ios 5模拟器出现错误。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:'On iPad, UIImagePickerController must be presented via UIPopoverController'
但是它在4.3模拟器上工作
答案 0 :(得分:2)
从iOS5开始,您需要在弹出视图而不是模态视图中显示pickercontroller。
来自Apple文档:在iPad上,使用弹出窗口显示用户界面。仅当图像选择器控制器的sourceType属性设置为UIImagePickerControllerSourceTypeCamera时,这样做才有效。要使用弹出控制器,请使用UIPopoverController类参考中“演示和解除弹出窗口”中描述的方法。
以下是在弹出视图中显示UIImagePickerController的示例:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];