Ipad UIImagePickerController和UIPopoverController错误

时间:2010-05-12 12:53:48

标签: ipad uiimagepickercontroller uipopovercontroller

我正在使用此代码打开带有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 {

感谢您的帮助!

3 个答案:

答案 0 :(得分:7)

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

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

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

要取消弹出框,您可以拨打dismissPopoverAnimated:

[self.popoverController dismissPopoverAnimated:YES];

答案 1 :(得分:7)

此错误是由于我的功能需要一个条形按钮项目而我使用的是普通的ui按钮。

答案 2 :(得分: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];