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?
//popover
- (IBAction) save:(id)sender
{
if ([self startDateIsValid] && [self endDateIsValid])
{
[[self parentViewController] setDatesForEvent:startDate eventEndDate:endDate allDay:[allDaySwitch isOn]];
[self dismissModalViewControllerAnimated:YES];
}
}
//AddEventViewController_iPad
#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> {
//datePopover
#import <UIKit/UIKit.h>
#import "AddEventViewController_iPad.h"
@protocol DismissPopoverDelegate <NSObject>
- (void) dismissWithData:(NSString *)data;
@end
@interface dateViewPopOverViewController_iPad : UIViewController<UIPopoverControllerDelegate> {
Idea is simple. YourViewController
- it's viewController of UIPopoverController
. MainViewController
- controller where you create UIPopoverController
YourViewController
with dismiss method id<DismissDelegateProtocol>
in YourViewController
DismissDelegateProtocol
in MainViewController
DismissDelegateProtocol
in MainViewController
YourViewController
in MainViewController
set delegate property (yourViewController.delegate = self;
) [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;
@end
@class YourViewController : UIViewController
{
id<DismissPopoverDelegate> delegate;
}
@property (nonatomic, assign) id<DismissPopoverDelegate> delegate;
In YourViewController.m:
- (void) methodWhenYouWantToDismissPopover
{
[self.delegate dismissPopover:data];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With