Ollie177
Ollie177

Reputation: 315

How do I Dismiss a UIPopoverController when opening another using a BarButtonItem?

I'm quite new to Objective-C and so far I'm using a UIViewController and I've got Two UIPopoverControllers working within it but I want one to dismissPopoverAnimated when I open the other Here the code I've got so far for them:

-(IBAction)tabBtn1:(id)sender {

CapPhoto *capPhoto = [[CapPhoto alloc] init];
UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:capPhoto];
[pop setDelegate:self];
[pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[pop setPopoverContentSize:CGSizeMake(200, 200)];
[capPhoto release];

}

-(IBAction)tabBtn2:(id)sender {

NewPhoto *newPhoto = [[NewPhoto alloc] init];
UIPopoverController *pop2 = [[UIPopoverController alloc] initWithContentViewController:newPhoto];
[pop2 setDelegate:self];
[pop2 presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[pop2 setPopoverContentSize:CGSizeMake(200, 200)];
[newPhoto release];


}

So I've allocated two separate .xib files (CapPhoto & NewPhoto) as the PopoverControllers and I need one to dismiss when the other is called. Any ideas? cheers!

Upvotes: 0

Views: 564

Answers (1)

Ollie177
Ollie177

Reputation: 315

Here is an explanation on how to dismiss a UIPopoverController when opening another:

In your main viewcontroller.h file declare a UIPopover controller

@interface viewcontroller: UIViewController {

UIPopoverController *popOne;
UIPopoverController *popTwo;

}
- (IBAction)popOver:(id)sender; 
@Property (nonatomic, retain) UIPopoverController *popOne'
@Property (nonatomic, retain) UIPopoverController *popTwo'

then in your view controller.m file:

- (IBAction)popOver:(id)sender {
if ([popOne isPopoverVisible]) {
[popTwo dissmissPopoverAnimated:YES];
//in here is where you add things to your popover

//also note you can find tutorials on popovers this is just code to allow you to dismiss one when opening another. It'll make sense if you've followed a popover tutorial.

}
else {

[popOne dismissPopverAnimated:YES];

}
}

Boom. You're done!

Upvotes: 1

Related Questions