UIImagePickerController 在 iPad 中崩溃
-(IBAction)selectPressed:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
我正在 iPad 和 iPhone 模拟器上测试此代码。在 iPhone 模拟器中(以及在真实的 iPhone 上)没问题 - 会出现图库。但在iPad模拟器上(我没有设备),它崩溃了。有什么想法吗?
-(IBAction)selectPressed:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
I am testing this code on iPad and iPhone simulators. In the iPhone simulator (and on real iPhones too) it's ok - gallery appears. But on the iPad simulator (I don't have a device), it crashes. Any ideas why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请阅读设备日志中的异常消息:
在 iPad 上,UIImagePickerController 必须通过 UIPopoverController 呈现
Please read the exception messages in the device log:
On iPad, UIImagePickerController must be presented via UIPopoverController
麦克斯说:
现在看来,当 UIImagePickerController 的 sourceType 设置为 UIImagePickerControllerSourceTypeCamera 时,我们可以呈现 ModalViewController 和 UIImagePickerController。这一定是为了支持 iPad 2 的摄像头全屏视图。 Max 是正确的,当 sourceType 设置为其他任何值时,presentModalViewController 在 iPad 上崩溃。
Max said:
It now appears that we can presentModalViewController the UIImagePickerController when its sourceType is set to UIImagePickerControllerSourceTypeCamera. This must be to support the iPad 2's cameras in a full screen view. Max is correct that presentModalViewController crashes on iPads when sourceType is set to anything else.
在 iPad 上显示模态视图控制器时,该视图控制器还需要设置其 modalPresentationStyle 属性才能显示传入的视图。
以下是文档中可供您使用的选项:
When displaying a modal view controller on the iPad, that view controller also needs it's
modalPresentationStyle
property to be set in order to display the incoming view.Here are the options available to you from the documentation:
尝试将此代码用于 ipad 照片库,
或者
http://www.techotopia.com/index.php/An_Example_iOS_4_iPad_Camera_and_UIImagePickerController_Application_(Xcode_4) ) 参考..
try using this code for ipad photolibrary,
or
http://www.techotopia.com/index.php/An_Example_iOS_4_iPad_Camera_and_UIImagePickerController_Application_(Xcode_4) reference..