使用 xcode 模拟器 IOS 5 测试 ipad 2 摄像头
我正在使用 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 模拟器上运行
I am testing ipad camera application with ipad simulator
I used below code, change the source type instead of camera.
-(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;
}
}
When it run in the simulator error came up in ios 5 simulator .
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:'On iPad, UIImagePickerController must be presented via UIPopoverController'
But its working on 4.3 simulator
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 iOS5 开始,您需要在弹出视图而不是模态视图中显示 pickercontroller。
来自苹果文档:在 iPad 上,使用弹出框呈现用户界面。仅当图像选择器控制器的 sourceType 属性设置为 UIImagePickerControllerSourceTypeCamera 时,这样做才有效。要使用弹出窗口控制器,请使用 UIPopoverController 类参考中的“呈现和关闭弹出窗口”中描述的方法。
http://developer.apple.com/ Library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
下面是一个展示弹出视图内的 UIImagePickerController:
Starting with iOS5 you need to show the pickercontroller in a popover view rather than a modal view.
From the apple documentation: On iPad, present the user interface using a popover. Doing so is valid only if the sourceType property of the image picker controller is set to UIImagePickerControllerSourceTypeCamera. To use a popover controller, use the methods described in “Presenting and Dismissing the Popover” in UIPopoverController Class Reference.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
Here is an example of presenting a UIImagePickerController inside a popover view: