Return to Video

01-13 Transitioning to Storyboard Button

  • 0:01 - 0:03
    Okay.
    Now, we want to connect up our
  • 0:03 - 0:05
    button the way we did for the label.
  • 0:05 - 0:09
    First, let's make a little room for the
    button by moving this label up a bit.
  • 0:09 - 0:12
    And, we'll need to open up our utilities
    pane, so we can drag in the button.
  • 0:15 - 0:17
    There we go.
  • 0:17 - 0:21
    While we have this utilities pane on
    the right open, let's go ahead and
  • 0:21 - 0:24
    set the titles on this button and label.
  • 0:24 - 0:28
    To do that, you're going to want to
    go to the attributes inspector, and
  • 0:28 - 0:30
    then you can see,
    here's where our title gets set.
  • 0:32 - 0:33
    We'll just say Click.
  • 0:34 - 0:38
    And then, for the label, let's just
    set it's original text to zero.
  • 0:38 - 0:43
    Let's close our utilities pane for
    now and move this back to the center.
  • 0:43 - 0:47
    And next up, we're going to set
    target action on this button.
  • 0:47 - 0:49
    First up, let's open up our
    view controller file for
  • 0:49 - 0:52
    a little review on target action.
  • 0:52 - 0:55
    Recall that the target action
    that we added programatically
  • 0:55 - 0:57
    had three key components.
  • 0:57 - 1:02
    Its target, which was self, the action,
    which was the method increment count,
  • 1:02 - 1:05
    and the event that would trigger
    that action, touch up inside.
  • 1:07 - 1:09
    So, now, we're going to use
    storyboard to tie together these
  • 1:09 - 1:11
    same three pieces of information.
  • 1:12 - 1:15
    But first, we need to mark
    this method as an IB action
  • 1:15 - 1:17
    to that it actually
    shows up in story board.
  • 1:19 - 1:22
    Similar to how we did
    with the label property.
  • 1:23 - 1:26
    And, we can close our
    assistant editor for now and
  • 1:26 - 1:29
    focus on story board, and
    then move this over a bit.
  • 1:29 - 1:34
    And, to set our target action,
    first we bring up the button's
  • 1:34 - 1:38
    pop up connections menu,
    go down to touch up inside,
  • 1:38 - 1:42
    drag to our view controller, and choose
    the method we want our to be our action.
  • 1:43 - 1:46
    I'm just going to remove that
    target action really quick, so
  • 1:46 - 1:49
    I can show you how to
    make it one other way.
  • 1:49 - 1:52
    Using the canvas view,
    you can still get to this menu.
  • 1:52 - 1:56
    Go from touch up inside to
    the view controller, and
  • 1:56 - 1:58
    then the method increment count.
  • 1:58 - 2:02
    And, you can see the three key
    components of the target action.
  • 2:02 - 2:06
    Let's go ahead and run it so
    we can see it in action.
  • 2:06 - 2:09
    And if we click on the button,
    we can see our count incrementing.
  • 2:09 - 2:12
    So, that ought to take
    care of click counter.
  • 2:12 - 2:15
    Remember how our label
    had an optional type?
  • 2:15 - 2:16
    Next up,
  • 2:16 - 2:19
    Jason's going to tell you all about
    optionals in the first Swift session
Title:
01-13 Transitioning to Storyboard Button
Description:

01-13 Transitioning to Storyboard Button

more » « less
Video Language:
English
Team:
Udacity
Project:
UD788 - UIKit Fundamentals
Duration:
02:20

English subtitles

Revisions Compare revisions