1

我创建了一个应用程序并有“图库”按钮,我想在按下该按钮时可以看到 Ipad 照片库中的所有图像。我的代码在这里:

- (IBAction)btGallery:(id)sender {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    if(popoverController == nil)
    {
        popoverController = [[UIPopoverController alloc] initWithContentViewController:picker];
    }
    popoverController.delegate = self;
    [popoverController presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}

但是当我按下那个按钮时,我什么都看不到……请帮帮我!

4

1 回答 1

2

我以编程方式完成了它,它为我工作。在您的按钮方法中添加此代码

确保更改 ivars 的名称

self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.picker.delegate = self;

self.popOver = [[UIPopoverController alloc] initWithContentViewController:self.picker];

[self.popOver presentPopoverFromRect:CGRectMake(10, 30, 200, 350)
                                   inView:self.view
                                permittedArrowDirections:UIPopoverArrowDirectionUp
                                 animated:YES];}

这应该对你有用,如果你不能,请通知。

于 2013-03-09T13:37:22.733 回答