Dismissing and Opening a UIPopOver with one UIToolBarItem Button?

混江龙づ霸主 提交于 2019-12-25 00:31:59

问题


I was wondering how I could use 1 button on my ToolBar to open and dismiss my UIPopOver. If I keep tapping the button right now, another PopOver overlaps the previous one. I want ONE button to be able to dismiss and open my PopOver. I tap once, it opens. I tap the button again, it dismisses. Please tell me how. Thanks


回答1:


In your button tap action event:

if (myPopover.popoverVisible)  //self.myPopover if using property
{
    [myPopover dismissPopoverAnimated:YES];
    return;
}

//continue code here to create/present your MyPopover…



回答2:


Quick way to do it is to define a UIPopOverController property in your presenting view controller and use this property to instantiate your popover (and accompanying content view controller).

In your presenting view controller you'll need something like:

UIViewController *aViewController = [[UIViewController alloc]init];
self.popOverController = [[UIPopoverController alloc] initWithContentViewController:aViewController]; 

Then in your button's action to toggle the popOver it should do something like:

    if(self.popOverController.popoverVisible) {
    [self.popOverController dismissPopoverAnimated:YES];
    } else { //Display the popover }

Hope that help



来源:https://stackoverflow.com/questions/10645529/dismissing-and-opening-a-uipopover-with-one-uitoolbaritem-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!