iPhone 和 iPad 的条件编码在现实中是如何工作的?

发布于 2024-11-09 07:09:21 字数 740 浏览 8 评论 0原文

UIImagePicker 在 iPhone 和 iPad 上的呈现方式必须不同。在 iPad 上,它会抛出一个异常:

* 由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因: '在 iPad 上,UIImagePickerController 必须 通过 UIPopoverController'

呈现

所以我必须将代码添加到 iPad 特定的通用应用程序中。有什么安全的方法可以使应用程序不会在缺少 UIPopoverController 的设备上崩溃?

示例:

popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
        [popover presentPopoverFromRect:CGRectMake(100, 100.0, 0.0, 0.0) 
                                 inView:self.view
               permittedArrowDirections:UIPopoverArrowDirectionAny 
                               animated:YES];

另外,如果我需要 UIPopoverController,我需要一个保存它的实例变量。我该如何处理这个问题?

UIImagePicker must be presented differently on iPhone and iPad. On the iPad, it throws an exception saying this:

* Terminating app due to uncaught exception
'NSInvalidArgumentException', reason:
'On iPad, UIImagePickerController must
be presented via UIPopoverController'

So I must add code to my universal app which is iPad specific. What is a safe way to do it so that the app won't crash on devices which lack a UIPopoverController?

Example:

popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
        [popover presentPopoverFromRect:CGRectMake(100, 100.0, 0.0, 0.0) 
                                 inView:self.view
               permittedArrowDirections:UIPopoverArrowDirectionAny 
                               animated:YES];

Also, in case I need a UIPopoverController, I need an instance variable that holds it. How would I handle this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

<逆流佳人身旁 2024-11-16 07:09:21

您可以通过执行此操作来检查某个类是否存在。

Class popoverClass = (NSClassFromString(@"UIPopoverController"));
if (popoverClass != nil) {
// you're on ipad
} else {
// you're on iphone/ipod touch
}

You can check to see if a class exists by doing this.

Class popoverClass = (NSClassFromString(@"UIPopoverController"));
if (popoverClass != nil) {
// you're on ipad
} else {
// you're on iphone/ipod touch
}
无风消散 2024-11-16 07:09:21

您可以快速检查您使用的设备:

[[UIDevice currentDevice] model];

You can do a quick check of which device you are on with:

[[UIDevice currentDevice] model];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文