Ipad UIImagePickerController and UIPopoverController error

廉价感情. 提交于 2019-12-10 13:50:03

问题


I am using this code to open a popover with 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];

But this results in this error request for member 'popoverController' in something not a structure or union and this error 'popoverController' undeclared (first use in this function).

Also I want to dismiss the popover when the image is selected.

What code should I put in the following function to dismiss the popover once the image is selected.

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

Thanks for the help!


回答1:


The error means popoverController hasn't been declared in the view controller. You need to add it to the interface as an ivar and property (it's not built-in):

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

In the implementation, add the @synthesize, set it to nil in viewDidUnload, and release in dealloc.

To dismiss the popover, you would call dismissPopoverAnimated:.

[self.popoverController dismissPopoverAnimated:YES];



回答2:


This error was caused becaused my function requires a bar button item and i was using a normal ui button.




回答3:


try using this code :

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];


来源:https://stackoverflow.com/questions/2818919/ipad-uiimagepickercontroller-and-uipopovercontroller-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!