86360

Dismissing and Opening a UIPopOver with one UIToolBarItem Button?

Question:

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

Answer1:

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…

Answer2:

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

Recommend

  • How to install python module on Heroku cedar stack with Rails
  • UILocalNotification stop sound after notification is dismissed
  • ProgressDialog: How to prevent automatic dismissing of Dialog inside setButton-Listener?
  • undirected graphs algorithms
  • dot 2 pixels together
  • So we've got MEF working with MVC4, how about the convention based model?
  • Msql: Counting growth over time
  • PowerShell IComparable with subclasses
  • best layer for placing dependency injection related code in layered proeject
  • Why is my database not being updated when someone visits my website?
  • Go template remove the last comma in range loop
  • integrating GWT with CDI (Seam/Weld)
  • Assembly Language Absolute addresses and segment registers
  • Dependency Injection - Choose DLL and class implementation at runtime through configuration file
  • Trying to delete files older than X number of days on insert in .NET MVC
  • unable to get jsonEncode in magento2
  • Bootstrap (v3.3.4) glyphicons not displayed in IE when refresh page (F5)
  • Implementing “partial void” in VB
  • Sending HTML Form Data to Spring REST Web Service
  • d3 v4 drag and drop with TypeScript
  • JQuery Internet Explorer and ajaxstop
  • Database structure design with variable amounts of fields
  • why do I get the error when installing the gem 'pg'? [duplicate]
  • FileReader+canvas image loading problem
  • Why value captured by reference in lambda is broken? [duplicate]
  • How do I fake an specific browser client when using Java's Net library?
  • Opengl-es onTouchEvents problem or a draw problem? [closed]
  • How to get a value (ex: baseURL) in every Karate feature?
  • what is the difference between the asp.net mvc application and asp.net web application
  • Comma separated Values
  • Error creating VM instance in Google Compute Engine
  • Acquiring multiple attributes from .xml file in c#
  • Hits per day in Google Big Query
  • how does django model after text[] in postgresql [duplicate]
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Change div Background jquery
  • Linking SubReports Without LinkChild/LinkMaster
  • How can I remove ASP.NET Designer.cs files?
  • Checking variable from a different class in C#
  • java string with new operator and a literal