Question

Apple's "Mobile Human Interface Guidelines" says about Popovers:

When possible, allow people to close one popover and open a new one with one tap. This behavior is especially desirable when several different bar buttons each open a popover, because it prevents people from having to make extra taps.

The only solution I can think right now is to track the position of the touch when dismissing the popover and check whether that was the position of another button. Is there any easier way to do this?

PS: I searched in stackoverflow and googled quite a while before posting. Sorry, if this was asked here before.

UPDATE

I guess I didn't explain myself well. Let's say I have three buttons. All of them open a popover. My user taps button #1 and a popover opens. While the popover is open, the user taps button #2. The popover gets dismissed (because the user tapped outside of the popover - default behavior of non-modal popovers) and a new popover opens up because the user had clicked on button #2. All of that without having to tap twice: once to dismiss the popover and twice for opening the new one.

2nd UPDATE

I built a simple dummy to reproduce what I'm trying to do. When the user taps on a button and a popover is open, the method that opens the popovers doesn't get called. Therefore the user has to click twice to open the second popover. Any ideas?

#import "RootViewController.h"
#import "AViewController.h"

@interface RootViewController() 

@property (nonatomic, retain) UIPopoverController *currentPopover;

@end

@implementation RootViewController

@synthesize currentPopover;

- (void)loadView
{
    CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
    UIView *view = [[UIView alloc] initWithFrame:applicationFrame];

    CGRect buttonFrame = CGRectMake(50, 100, 200, 40);

    for (int i = 0; i < 3; i++) 
    {

        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button setTitle:[NSString stringWithFormat:@"Button %i", i + 1] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(openPopover:) forControlEvents:UIControlEventTouchDown];
        [button setFrame:buttonFrame];
        [view addSubview:button];

        buttonFrame.origin.y += 50;
    }


    self.view = view;
    [view release];
}

- (IBAction)openPopover:(id)sender
{
    AViewController *avc = [[AViewController alloc] init];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:avc];
    [avc release];

    UIPopoverController *tempPopover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
    [tempPopover setDelegate:self];
    [tempPopover setPopoverContentSize:CGSizeMake(320, 500)];
    [tempPopover presentPopoverFromRect:[sender frame] inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

    self.currentPopover = tempPopover;
    [tempPopover release];


    [navigationController release];
}

- (void)dealloc
{
    [currentPopover release];
    [super dealloc];
}

@end
Was it helpful?

Solution

If you use bar button items in a toolbar, the open popover is not automatically closed when you tap another bar button item. In these situations you should close the visible popover and open the other one in one step.

OTHER TIPS

- (IBAction)sortAction {
[searchBarView resignFirstResponder];
[self.popoverController dismissPopoverAnimated:YES]; //clear popover

self.popoverController = popoverSetting;
[self.popoverController presentPopoverFromBarButtonItem:sortBarButtonItem
                               permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; //show popover
}

hope will help you

Lets say you have 3 buttons and each opens a popup. You could use a state variable that tracks whether a popup is currently open, and inside each "open popup" method, close the existing one (if it is open) before opening the new popup.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top