【问题标题】:camera library issue [duplicate]相机库问题[重复]
【发布时间】:2012-09-06 14:06:05
【问题描述】:

可能重复:
UIPopover for iphone 4.0

我在 Xcode 中有一个通用应用程序。如果用户使用的是 iPad,则使用库中的图像按钮效果很好。但是,如果他们使用 iPhone,则该按钮不起作用。

这是我收到的错误。

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIPopoverController initWithContentViewController:] 在 UIUserInterfaceIdiomPad 下未运行时调用。”

请帮忙!

这是我的代码。

- (IBAction) useCameraRoll: (id)sender
{

if ([self.popoverController isPopoverVisible]) {
[self.popoverController dismissPopoverAnimated:YES];

} else {
if ([UIImagePickerController isSourceTypeAvailable:
     UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
    UIImagePickerController *imagePicker =
    [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType =
    UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.mediaTypes = [NSArray arrayWithObjects:
                              (NSString *) kUTTypeImage,
                              nil];
    imagePicker.allowsEditing = YES;

    newMedia = NO;
}
}
}

如何合并以下代码? if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 在此处添加弹出框代码} else {
在此处添加弹出框的替代方案}

【问题讨论】:

    标签: iphone camera xcode4.3


    【解决方案1】:

    崩溃的原因是 UIPopoverController 仅适用于 iPad,在 iPhone 上运行时无法使用。所以你需要寻找替代品。

    【讨论】:

    • 如果您想在 iPhone stackoverflow.com/a/4124016/1451709987654321@ 中制作与 UiPopoverController 非常相似的东西,请尝试此答案
    • 有没有办法为 iPad 保留它并为 iPhone 删除它?
    • 是的,你可以实现它。只需检查应用程序是否在 Iphone 或 Ipad 上运行。使用以下代码 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { Add Popover code here } else { Add Alternative for popover here }
    • Ok Sahil 我在这个问题中添加了我的代码。请告知我将如何使用您的代码。谢谢
    • 您需要将此代码添加到您将弹出框添加到应用程序中的位置。它应该看起来像 - self.popoverController = [[UIPopoverController alloc] initWithContentViewController:View]; [popover presentPopoverFromRect:CGRectMake(button.frame.size.width / 2, button.frame.size.height / 1, 1, 1) inView:button allowedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-02
    相关资源
    最近更新 更多