Possible Duplicate:
How to Dismiss a Storyboard Popover
I have a iPad storyboard. A Bar Button Item in one View is Control-dragged to another view -- and a popover style is chosen. When I press the button the new popover view is shown in a popover, but I have two problems:
- When I press the button again, another instance of the popover view is displayed -- I can see, that the black border is getting darker and darker. If the popover view is open and I press the button, the popover view should dismiss. How can I do that?
- Currently the new popover view is floating to the button of the screen even if the content in the view is not that heigh. How can I control the dimensions of the popover view?
EDIT1:
I've created a segue by dragging from the yellow controller icon in the bottom of the controller to the other view, which should be inside the popover. The identifier for this popover is settingsPopover.
I then do this inside the IBAction:
- (IBAction)settingsButtonTapped:(id)sender {
[self performSegueWithIdentifier:@"settingsPopover" sender:self];
}
But this gives me this error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIStoryboardPopoverSegue must be presented from a bar button item or a view.'
Have I created the segue in a bad way or in the call to performSegueWithIdentifier
wrong?
EDIT2:
I've created this IBAction:
- (IBAction)settingsButtonTapped:(id)sender {
if (_settingsPopover == nil) {
SettingsViewController* settingsView = [[SettingsViewController alloc] initWithStyle:UITableViewStylePlain];
self.settingsPopover = [[UIPopoverController alloc] initWithContentViewController:settingsView];
}
[self.settingsPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
It almost work, but one drawback is that it is not using the UIView designed in my Storyboard. For instance, in my storyboard the view that has the class SettingsViewController in designed as a grouped table view. Is there a way to display the UIView designed in the storyboard inside the popover instead of the raw SettingsViewController instance?
Solution:
I created a global segue in the Storyboard with the identifier "settingsPopover".
- (IBAction)settingsButtonTapped:(id)sender {
if (self.settingsPopover==nil) {
[self performSegueWithIdentifier:@"settingsPopover" sender:sender];
}
}
#pragma mark - UIView
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"settingsPopover"]) {
self.settingsPopover = [(UIStoryboardPopoverSegue *)segue popoverController];
self.settingsPopover.delegate = self;
}
}
#pragma mark - UIPopoverControllerDelegate
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
self.settingsPopover = nil;
}