通用Xcode相机胶卷应用问题

时间:2012-09-06 15:55:48

标签: iphone ipad camera xcode4.3 ios-universal-app

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

这是我收到的错误。

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

被告知此代码可行。它是否会进入下面的(IBAction)代码?

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { Add Popover code here } else {     
Add alternative for popover here }

- (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;
    }
}
}

1 个答案:

答案 0 :(得分:0)

这次崩溃正在发生,因为你不能在iPhone上使用UIPopOverControllers,只能在iPad上使用。

  

[UIPopoverController initWithContentViewController:]在时调用   在UIUserInterfaceIdiom Pad 。'

下运行

尝试这样的事情:

- (IBAction)useCameraRoll:(id)sender
{
    UIPopoverController *popoverController = [[UIPopoverController alloc] init];
    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 ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        if (popoverController.isPopoverVisible) {
            [popoverController dismissPopoverAnimated:YES];
        }else{
                [popoverController setContentViewController:imagePicker];
                [popoverController setDelegate:self];
                [popoverController presentPopoverFromRect:CGRectMake(0, 0, 320, 320) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        }
    }else{
        [imagePicker presentViewController:imagePicker animated:YES completion:nil];
    }
}