Adding a modal

Let's review the design for the section header:

Note that we have a + Location button that will display our locations. Let's add that modal now:

  1. While in the Main.storyboard file, select the object library and, in the filter field at the bottom of the Library pane, type button.
  1. Drag and drop the Button component into the section header we created in our Explore View Controller:

Ignore the layout warning. We will format the button later regarding location and size, and that will get rid of the warning.

Next, we need to add another View Controller to our storyboard:

  1. In the filter, type viewcontroller, and drag and drop the ViewController component above the Explore View Controller in Main.storyboard.
  2. With the View Controller selected, navigate to Editor | EmbedIn | NavigationController.

  1. Control + drag from where it says Button in the View Controller, under the Explore tab, to the Navigation Controller that was just created (you can also do this within Outline view, by Control + dragging from the button to the new Navigation Controller you just created):
  1. When you let go, you will be presented with the following menu, and you should select Present Modally:

Now, let's run the project by hitting the Play button (or use command + R). You will see that our button now launches a modal. In the next chapter, we will make this button match our design:

Currently, as you can see in the preceding screenshot, we cannot dismiss this modal. Therefore, we need a cancel button and a done button to dismiss the view. Let's fix this:

  1. Open Main.storyboard and then go to your View Controller (not the Navigation Controller) of your modal:
  1. Open the object library (command + Shift + L) and type bar button into the filter area of the objects library in the Utilities Panel.
  1. Drag and drop a Bar Button Item into the right-hand side of the Navigation Bar of your View Controller Scene:
  1. Drag another Bar Button Item into the left-hand side of the Navigation Bar.
  1. You should have two Bar Button Items that both say Item:
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.254.122