0

I've been learning a lot about popovers and found out how to get them to dismiss gracefully using delegates. The issue I have now is that there is a popup in my program that is controlled with a UINavigationController.

When the user presses a button on my parent ViewController, the popover comes up as it should and the user can navigate through 3 scenes using tables. Everything works fine until it comes time to dismiss the pop over.

On the final scene I would like to dismiss the popover whenever the user presses an index. If I didn't have the UINavigationController attached to these views it would be easy. I don't know how to implement the delegate.

I tried making a delegate in my UINavigationController implementation, but XCode tells me that UINavigationController already has a delegate. Is there some way to use the delegate that is already there?

Any help would be greatly appreciated.

4

2 回答 2

1

i think using a notification might be better in this case, since your controller from which you want to start the dismissal is far removed from the popover controller which should do the dismissal (so it would be hard to set the delegate). If you're using a popover segue in a storyboard, you can get a reference to the popover controller from the segue object. From the controller which initiates the popover segue, I put this code:

@implementation ViewController {
    UIPopoverController *pop;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissPopover) name:@"DismissPopoverNotification" object:nil];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    pop = [(UIStoryboardPopoverSegue *)segue popoverController];
}

-(void)dismissPopover {
    [pop dismissPopoverAnimated:YES];
}

And in the last controller, where choosing a row in a table causes the popover to be dismissed, you could have this code in the didSelectRowAtIndexPath method:

[[NSNotificationCenter defaultCenter] postNotificationName:@"DismissPopoverNotification" object:self];
于 2013-01-26T01:11:20.213 回答
0

I use notifications quite a bit to relay data back and forth. This additional line, I was unaware of...

pop = [(UIStoryboardPopoverSegue *)segue popoverController];

Yet, I do want to point out one tiny detail that was missed...

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissPopover:) name:@"DismissPopoverNotification" object:nil];

There should be a colon after dismissPopover... see above. Without it, the compiler was crashing.

Other than that... I want to say thanks for this! It helped with one dismissal issue, and I'm going to try it on another.

于 2013-01-28T13:40:47.280 回答