UIImagePicker 在 iPhone 和 iPad 上的呈现方式必须不同。在 iPad 上,它会抛出一个异常:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'On iPad, UIImagePickerController must be presented via 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,我需要一个实例变量来保存它。我该如何处理?
最佳答案
您可以通过执行此操作来检查类是否存在。
Class popoverClass = (NSClassFromString(@"UIPopoverController"));
if (popoverClass != nil) {
// you're on ipad
} else {
// you're on iphone/ipod touch
}
关于objective-c - iPhone 和 iPad 的条件编码在现实中是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6112450/