Take the 2-minute tour ×

I am trying to dismiss a UIPopoverViewControler from a button in the Popover. In addition I want it to transfer the data back to the main view. I have it working for a modalViewController but not for a Popover. Does anyone know how I can achieve this?


    - (IBAction) save:(id)sender {
if ([self startDateIsValid] && [self endDateIsValid]) {

    [[self parentViewController] setDatesForEvent:startDate eventEndDate:endDate allDay:[allDaySwitch isOn]];
[self dismissModalViewControllerAnimated:YES];




#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "dateViewPopOverViewController_iPad.h"
@interface AddEventViewController_iPad : UIViewController <UITableViewDelegate,     UITableViewDataSource, MFMailComposeViewControllerDelegate, UITextFieldDelegate,  UIAlertViewDelegate,UIPopoverControllerDelegate,UINavigationControllerDelegate,UIPopoverControllerDelegate,ABPeoplePickerNavigationControllerDelegate, ABNewPersonViewControllerDelegate,DismissPopoverDelegate> {


#import <UIKit/UIKit.h>
#import "AddEventViewController_iPad.h"
@protocol DismissPopoverDelegate <NSObject>

- (void) dismissWithData:(NSString *)data;


@interface dateViewPopOverViewController_iPad : UIViewController     <UIPopoverControllerDelegate> {
share|improve this question

3 Answers 3

up vote 22 down vote accepted

Idea is simple. YourViewController - it's viewController of UIPopoverController. MainViewController - controller where you create UIPopoverController

  1. Declare protocol in YourViewController with dismiss method
  2. Declare property of type id<DismissDelegateProtocol> in YourViewController
  3. Declare support of DismissDelegateProtocol in MainViewController
  4. Implement dismiss method of DismissDelegateProtocol in MainViewController
  5. When you create YourViewController in MainViewController set delegate property (yourViewController.delegate = self;)
  6. In action, that response to button touching call delegate method: [self.delegate dismissWithData:dataToTransfer];

In code it should be like this:

In MainViewController.h:

#import "YourViewController.h"
@class MainViewController: UIViewController < DismissPopoverDelegate >

In MainViewController.m:

- (void) dismissPopover:(NSObject *)yourDataToTransfer
{ /* Dismiss you popover here and process data */ }

// Some method, when you create popover
    YourViewController *vc = ... ;
    vc.delegate = self; // this delegate property should be declared as assign

In YourViewController.h:

@protocol DismissPopoverDelegate
- (void) dismissPopover:(NSObject *)yourDataToTransfer;

@class YourViewController : UIViewController
    id<DismissPopoverDelegate> delegate;

@property (nonatomic, assign) id<DismissPopoverDelegate> delegate;

In YourViewController.m:

- (void) methodWhenYouWantToDismissPopover
    [self.delegate dismissPopover:data];
share|improve this answer
im getting an error on the line @class YourViewController : UIViewController { id<DismissPopoverDelegate> delegate; } it says i need a ; –  BDGapps May 7 '11 at 16:24
What kind of error you've get? –  5hrp May 7 '11 at 16:30
it says i need a ; instead in @class AddEventViewController_iPad : UIViewController –  BDGapps May 7 '11 at 16:32
what are u considering as the YourViewController.h and the MainViewController.h –  BDGapps May 7 '11 at 16:35
I've create example project for you. Get it here –  5hrp May 7 '11 at 17:44

Sharrps answer is perfectly good, but here's a slightly different approach that may be quicker if you're presenting a subclassed view controller.

So if you've subclassed the UIViewController that's being presented, define a property on it pointing to a UIPopoverController. In your presenting view controller, instantiate your custom view controller, instantiate your popover with said custom view controller, then assign the custom view controller it's property to point to the popover controller containing it.

When it comes time to dismiss, your controller has a reference to it's popover and can dismiss it. The popover will also have a pointer to it's parent view controller, so you can perform any actions you need with regards to your model via your original presenting view controller.

share|improve this answer
This is smart. I am going to shun the accepted answer and go this way. Apple should have made this simpler. When you ask a fellow to get out and he says, ask my father to take me away, it can be pretty annoying. –  gigahari Mar 21 '13 at 10:01
Way easier than accepted answer—am accustomed to passing objects and data amongst classes this way, but didn't think of implementing dismissing the popover like this from within the presented VC. –  Evan R Mar 12 at 15:51

In the original dialogue above "im getting an error on the line @class YourViewController : UIViewController { id delegate; } it says i need a ; – BDGapps"

The answer is very simple. It's a type. Change @class to @interface and all is well.

@protocol DismissPopoverDelegate
- (void) dismissPopover:(NSObject *)yourDataToTransfer;

@interface YourViewController : UIViewController {
    id<DismissPopoverDelegate> delegate;
share|improve this answer

Your Answer


