在iPad中显示照片库

时间:2013-12-31 03:08:02

标签: ios uiimagepickercontroller uipopovercontroller

这是我使用UIPopoverController从iPad显示照片库的代码。 它给错误说错误的选择器被传递给实例。

    UIImagePickerController *imagpicker=[[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    [imagpicker setSourceType:UIImagePickerControllerSourceTypeCamera];
}
else{

    [imagpicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
[imagpicker setAllowsEditing:YES];
[imagpicker setDelegate:self];
self.po=[[UIPopoverController alloc] initWithContentViewController:imagpicker];
//self.po.delegate=self;
[po setDelegate:self];

[[self po] presentPopoverFromRect:image.bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

1 个答案:

答案 0 :(得分:0)

嗨,如果你想在不使用UIPopoverController的情况下这样做 请试试这段代码。

UIImagePickerController *imagpicker=[[UIImagePickerController alloc] init];
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        [imagpicker setSourceType:UIImagePickerControllerSourceTypeCamera];
    }
    else{

        [imagpicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    }
    [imagpicker setAllowsEditing:YES];
    [imagpicker setDelegate:self];
    [self presentViewController:imagpicker animated:YES completion:nil];

希望这会对你有所帮助。