YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← 01-13 Transitioning to Storyboard Button

01-13 Transitioning to Storyboard Button

Get Embed Code
1 Language

Showing Revision 2 created 04/08/2015 by Udacity Robot.

  1. Okay.
    Now, we want to connect up our

  2. button the way we did for the label.
  3. First, let's make a little room for the
    button by moving this label up a bit.
  4. And, we'll need to open up our utilities
    pane, so we can drag in the button.
  5. There we go.
  6. While we have this utilities pane on
    the right open, let's go ahead and
  7. set the titles on this button and label.
  8. To do that, you're going to want to
    go to the attributes inspector, and
  9. then you can see,
    here's where our title gets set.
  10. We'll just say Click.
  11. And then, for the label, let's just
    set it's original text to zero.
  12. Let's close our utilities pane for
    now and move this back to the center.
  13. And next up, we're going to set
    target action on this button.
  14. First up, let's open up our
    view controller file for
  15. a little review on target action.
  16. Recall that the target action
    that we added programatically
  17. had three key components.
  18. Its target, which was self, the action,
    which was the method increment count,
  19. and the event that would trigger
    that action, touch up inside.
  20. So, now, we're going to use
    storyboard to tie together these
  21. same three pieces of information.
  22. But first, we need to mark
    this method as an IB action
  23. to that it actually
    shows up in story board.
  24. Similar to how we did
    with the label property.
  25. And, we can close our
    assistant editor for now and
  26. focus on story board, and
    then move this over a bit.
  27. And, to set our target action,
    first we bring up the button's
  28. pop up connections menu,
    go down to touch up inside,
  29. drag to our view controller, and choose
    the method we want our to be our action.
  30. I'm just going to remove that
    target action really quick, so
  31. I can show you how to
    make it one other way.
  32. Using the canvas view,
    you can still get to this menu.
  33. Go from touch up inside to
    the view controller, and
  34. then the method increment count.
  35. And, you can see the three key
    components of the target action.
  36. Let's go ahead and run it so
    we can see it in action.
  37. And if we click on the button,
    we can see our count incrementing.
  38. So, that ought to take
    care of click counter.
  39. Remember how our label
    had an optional type?
  40. Next up,
  41. Jason's going to tell you all about
    optionals in the first Swift session