0
votes

i am new in ios .I have a navigation bar that contains multiple buttons, including a back button, sort ,filter,settings button and a button that opens a popover . UIPopoverController not dismissed when opened from navigationItem inside UINavigationController.

When i click filter navigation item popoverView controller working fine but the problem is if i click other navigation items like back,sort,setting not dismissing.when i tap or touch on navigation bar popover not dismissing how to rectify this problem?

viewController.h

    IBOutlet UINavigationBar *navigationBar;

viewController.m

UIBarButtonItem *leftButton = [UIBarButtonItem barItemWithImage:[UIImage imageNamed:@"back_btn.png"] target:self action:@selector(onBack)];

UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@""];

UIButton *btnMainLogo = [UIButton buttonWithType:UIButtonTypeCustom];

[btnMainLogo setImage:[UIImage imageNamed:@"dina_new_logo.png"] forState:UIControlStateNormal];
btnMainLogo.frame = CGRectMake(0, 0, 160, 36);
[btnMainLogo addTarget:self action:@selector(onHome) forControlEvents:UIControlEventTouchUpInside];
item.titleView = btnMainLogo;

item.leftBarButtonItem = leftButton;
item.hidesBackButton = YES;

//RIGHT MENU
NSMutableArray *arrRightBarItems = [[NSMutableArray alloc] init];
UIButton *btnSetting = [UIButton buttonWithType:UIButtonTypeCustom];
[btnSetting setImage:[UIImage imageNamed:@"settings.png"] forState:UIControlStateNormal];
btnSetting.frame = CGRectMake(0, 0, 32, 32);
btnSetting.showsTouchWhenHighlighted=YES;
[btnSetting addTarget:self action:@selector(onSettings:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnSetting];

UIButton *btnShare = [UIButton buttonWithType:UIButtonTypeCustom];
[btnShare setImage:[UIImage imageNamed:@"share-icon.png"] forState:UIControlStateNormal];
btnShare.frame = CGRectMake(0, 0, 32, 32);
btnShare.showsTouchWhenHighlighted=YES;
[btnShare addTarget:self action:@selector(onShare:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem1 = [[UIBarButtonItem alloc] initWithCustomView:btnShare];

UIBarButtonItem *edit = [[UIBarButtonItem alloc]
                           initWithTitle:@"Edit"
                           style:UIBarButtonItemStylePlain
                           target:self
                           action:@selector(onEditIssue:)];
UIBarButtonItem *sortByDate = [[UIBarButtonItem alloc]
                         initWithTitle:@"Sort"
                         style:UIBarButtonItemStylePlain
                         target:self
                         action:@selector(onSortByDate:)];
UIBarButtonItem *FilterByIssue = [[UIBarButtonItem alloc]
                         initWithTitle:@"Filter"
                         style:UIBarButtonItemStylePlain
                         target:self
                         action:@selector(onFilterByIssue:)];



NSArray *arrBtns = [[NSArray alloc]initWithObjects:barButtonItem,barButtonItem1,edit,sortByDate,FilterByIssue, nil];
[arrRightBarItems addObjectsFromArray:arrBtns];
[item setRightBarButtonItems:arrRightBarItems];
[navigationBar pushNavigationItem:item animated:NO];
2

2 Answers

0
votes

Try dismissing the popover in the callbacks for each bar button item. For instance:

-(void)onEditIssue:(id)sender
{
    if ([popoverController isPopoverVisible])
        [popoverController dismissPopoverAnimated:YES];
    //Do other stuff
}
0
votes

This question's accepted answer worked for me. Set the popover controller's passthroughViews to nil just after presenting it.