5

我正在使用此代码使用 imagepicker 打开一个弹出窗口

-(IBAction)photosAction:(id)sender 
{
// dismiss any left over popovers here
UIImagePickerController* picker = [[UIImagePickerController alloc] init]; 
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
picker.delegate = self; 

UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
self.popoverController = popover;          
popoverController.delegate = self;
[popoverController presentPopoverFromBarButtonItem:sender  permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[picker release];

但这会导致对成员“popoverController”的此错误请求不是结构或联合,并且此错误“popoverController”未声明(在此函数中首次使用)

我还想在选择图像时关闭弹出框。

选择图像后,我应该在以下函数中输入什么代码来关闭弹出框。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

谢谢您的帮助!

4

3 回答 3

7

该错误意味着 popoverController 尚未在视图控制器中声明。您需要将其作为 ivar 和属性添加到界面中(它不是内置的):

@interface ... {
     ...
     UIPopoverController *popoverController;
}
@property (nonatomic, retain) UIPopoverController *popoverController;
@end

在实现中,添加@synthesize,在viewDidUnload中设置为nil,在dealloc中释放。

要关闭弹出框,您可以调用dismissPopoverAnimated:

[self.popoverController dismissPopoverAnimated:YES];
于 2010-05-12T13:20:30.717 回答
7

这个错误是因为我的函数需要一个条形按钮项而我使用的是普通的 ui 按钮。

于 2010-05-17T09:56:26.840 回答
0

尝试使用此代码:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0) 
                         inView:self.view
       permittedArrowDirections:UIPopoverArrowDirectionAny 
                       animated:YES];
于 2013-01-22T08:49:07.013 回答