iPhone 和 iPad 的条件编码在现实中是如何工作的?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过执行此操作来检查某个类是否存在。
You can check to see if a class exists by doing this.
这个问题看起来像是以下问题的重复:
是否有特定的为 iPad 编译时设置的 Xcode 编译器标志?
This question looks like a dup of:
Is there a specific Xcode compiler flag that gets set when compiling for iPad?
您可以快速检查您使用的设备:
You can do a quick check of which device you are on with: