views:

2288

answers:

2

Hi,

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  A: 

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];
DyingCactus
Thanks, this solved the errors. But when I click on the button which is supposed to load the popover I get these errors in Console. *** -[UIRoundedRectButton view]: unrecognized selector sent to instance 0x4d1e140Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIRoundedRectButton view]: unrecognized selector sent to instance 0x4d1e140
nishantcm
What action have you set for the button click? Show the code that creates the button. Make sure selector in addTarget says "photosAction:" with colon at end. Of if button is created in IB, check the connection for touch-up-inside.
DyingCactus
IBOutlet UIButton * selectImageBtn;@property (nonatomic,retain) IBOutlet UIButton * selectImageBtn;@synthesize selectImageBtn
nishantcm
Now, when I put this code it works.UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:picker]; [aPopover setPopoverContentSize:CGSizeMake(320, 320)]; [aPopover presentPopoverFromRect:CGRectMake(200,200,-100,-100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; self.popoverController1 = aPopover;
nishantcm
Not so sure whether it's a good idea to retain the popoverController. I guess the popoverController is also retaining the contentsViewController and probably releasing it in it's dealloc, which will cause them never to release each other.
Martijn Thé
A: 

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

nishantcm
http://mobiforge.com/designing/story/using-popoverview-ipad-app-development
nishantcm