Popover controller not dismiss when click on other bar button but dismiss when click other button(or outside popover)

StackOverflow https://stackoverflow.com/questions/15827128

質問

I show a popover using - "presentPopoverFromBarButtonItem" - after that the popover will not dismiss when I click on the other bar button item in right navigation bar buttons.

But dismiss the popover when I click elsewhere. Also the issue is not there when we show popover using - " presentPopoverFromRect: inView: " - strange?.

Since we don't get the frame from UIBarButtonItem How can I show a popover correctly from barbutton.

thanks,

役に立ちましたか?

解決

Answering my own question to help some one,

// Presenting from BarButton will not dismiss popover when we click on other bar button.
// [self.popoverController presentPopoverFromBarButtonItem:self.barButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

NSMutableArray* buttons = [[NSMutableArray alloc] init];
for (UIView *subview in self.navigationController.navigationBar.subviews) {
    if ([subview isKindOfClass:[UIControl class]])   {
        [buttons addObject:subview];
    }
}

UIView *view = [buttons objectAtIndex:1]; // The '1' is the index to your bar item in the array of .items

CGRect barButtonFrame = [self.navigationController.navigationBar convertRect:view.frame toView:self.navigationController.view];
[self.popoverController presentPopoverFromRect:barButtonFrame inView:self.navigationController.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

What I did above is find the frame of bar button and show popover "presentPopoverFromRect".

他のヒント

I do no,whether you used nib or xib in popover controller or not,but let try below code

 if (_Popover != nil) {
        [_Popover dismissPopoverAnimated:YES];
    }
    else {
        [_Popover dismissPopoverAnimated:NO];
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top