Question

I am facing a weird issue with UIPopoverController. While creating the popover, we have set passthrough views property. We wanted to popover to close if we tap anywhere outside it.

[self.popover presentPopoverFromBarButtonItem:barButtonItemView
              permittedArrowDirections:UIPopoverArrowDirectionAny
              animated:YES];
// comment the below line if only toggle feature is expected to close the popover
[self.popover setPassthroughViews:self.tileMenu.tileMenuButtonsArray];

It works fine untill device's orientation changes. after orientation change, tapping outside has no effect. The method - popoverControllerShouldDismissPopover - is never called after orientation changes. If I tap on the button again, then it starts working fine. i.e. it relaunches the popover and closes the popover if i tap outside.

I am working on IOS 7 now.

Has anyone faced this issue before? any help will be appreciated.

Update: I tried dismissing and reopening the popover. It didn't work as well:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                     duration:(NSTimeInterval)duration
{
    if ( [self.popover isPopoverVisible] )
    {
        [self.popover dismissPopoverAnimated:NO];
        self.reopenPopover = YES;
    }
}

-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation        
{

    if (self.reopenPopover) {
    [self presentPopover:self.selectedTileMenuBarButtonItem];
    }
    self.reopenPopover = NO;
}

-(void) presentPopover:(UIBarButtonItem *) barButtonItemView {
    self.selectedTileMenuBarButtonItem = barButtonItemView;

    [self.popover presentPopoverFromBarButtonItem:barButtonItemView
                     permittedArrowDirections:UIPopoverArrowDirectionAny
                                     animated:YES];
    // comment the below line if only toggle feature is expected to close the popover
    [self.popover setPassthroughViews:self.tileMenu.tileMenuButtonsArray];
}
Was it helpful?

Solution

There was an issue with the implementation which I have fixed now and it worked. We had UIButtons and not UIBarButton but due to some earlier issue with method presentPopoverFromRect(there were issues when orientation of the ipad changes), we were presenting the popovers this way:

UIButton *control = (UIButton *) sender;
UIBarButtonItem *barButtonItemView = [[UIBarButtonItem alloc] init];        
[barButtonItemView setCustomView:control]; 
[self.popover presentPopoverFromBarButtonItem:barButtonItemView permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

it wasn't required. the below code fixed the issue:

[self.popover presentPopoverFromRect:[sender bounds] inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

// comment the below line if only toggle feature is expected to close the popover
[self.popover setPassthroughViews:self.tileMenu.tileMenuButtonsArray];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top