Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Popovers with Xcode Storyboards

How can I create a popover in an iPad Storyboard for an iOS 5.0+ app?

There's already one setup with the Xcode Project Template (Utility App), but I can't seem to figure out how Apple got it to work. I tried to mimic it, but only got errors. I even looked on Apple's Dev Site, but only got out-dated code that resulted in warnings and build errors.

I have a CBMainView and a CBMasterView (with the exception of the master view already included), and a UIToolbar with a UIToolbarButton. I need the user to tap the button on the UIToolbar, and up comes my 320x300 Popover (CBMasterView).

How can I do this with Xcode Storyboards? Tutorials, answers, code, or links are all appreciated!

like image 827
Sam Spencer Avatar asked Nov 23 '11 21:11

Sam Spencer


People also ask

How do I create a storyboard in Xcode?

From the File menu, choose New→New File... In the New File dialog, make sure you have selected the Resource subcategory of the iOS category on the left. Then choose the Storyboard item on the right and press Next (see Figure 4-24). In this screen, pick the Device Family for which you want to create your storyboard.

Can you have multiple storyboards Xcode?

Apple introduced them in iOS 9 and macOS 10.11. They do exactly what I needed. They allow you to break a storyboard up into multiple, smaller storyboards. A storyboard reference ties multiple storyboards together, creating one, large, composite storyboard.

How do I show popover in iOS?

Add a new file to the project, Select File -> New ->File and then select iOS -> Source -> Cocoa Touch Class. Name it PopoverViewController and make it a subclass of UIViewController. Go back to Main. storyboard and select the added View Controller.

Can you combine SwiftUI with storyboard?

The answer is YES! Here we will be discussing a simple way to use SwiftUI into our existing project, which already consists of a storyboard.


1 Answers

Before iOS 5, one would've needed to display another UIViewController using the First Responder via a Modal presentation (and a pile of code).

To create a popover in Xcode's Storyboard Mode (iOS 5+) use a UIButton or UIToolbarButton and create a Storyboard Segue between the button and the UIViewController that you want to pop-over.

Creating a segue between a button and another UIViewController is simple. Here's how:

  1. Click on the button in your storyboard and Control+Drag from the button to the UIViewController of choice. You should see a light blue line appear that extends from the button to the tip of your mouse.
  2. After dragging the blue line to the ViewController of choice a small black menu will appear. This menu displays the different segue options. Select Popover.

    Popover Segue Menu

  3. If everything was done correctly, this segue should be visible in the Connections Inspector when the button is selected:

Use Popover instead of Modal or Push

The UIViewController you create should also have a custom size that is smaller than the full screen. You can set a custom size by selecting the View Controller and setting its size property to freeform, or master (320 x 850).

like image 88
Sam Spencer Avatar answered Oct 21 '22 02:10

Sam Spencer