【问题标题】:UIPopoverController does not dismiss when clicking on the NavigationBar and NavigationBar items点击 NavigationBar 和 NavigationBar 项时 UIPopoverController 不会关闭
【发布时间】:2013-03-14 13:19:56
【问题描述】:

我是 ios 的新手。我有一个包含多个按钮的导航栏,包括一个后退按钮、排序、过滤器、设置按钮和一个打开弹出框的按钮。从navigationItem 内的UINavigationController 打开UIPopoverController 时不会关闭。

当我单击过滤导航项popoverView 控制器工作正常但问题是如果我单击其他导航项(如返回、排序、设置不关闭)。当我点击或触摸导航栏弹出框时不关闭如何纠正此问题?

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];

【问题讨论】:

    标签: ios uinavigationbar uinavigationitem


    【解决方案1】:

    尝试在每个条形按钮项的回调中解除弹出框。例如:

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

    【讨论】:

    • 我已经完成了,但是如果我触摸导航栏不会关闭不是导航项
    【解决方案2】:

    This 问题接受的答案对我有用。将弹出框控制器的 passthroughViews 设置为 nil

    【讨论】:

      猜你喜欢
      • 2011-09-02
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多