28 thoughts on “12. Handling button taps – Methods”

    • OMG, I fixed the error message. Found out what was causing it. It was redundant connections being linked. Solution for anyone having same prob: read the error message by scrolling right at the top and read it what hasn’e been linked. After that go to Mainstoryboard, and from very right panel click “Show the Connections inspector” tap, and hover over all the links you have there. Anything that’s not linked/responding to your mainstory board ui, just delete it. After all, re-run the code.

      Hope this helps!


  1. This is my code. It looks like yours…any suggestions?

    import UIKit

    class ViewController: UIViewController {

    @IBOutlet weak var rightImageView: UIImageView!
    @IBOutlet weak var leftImageView: UIImageView!
    @IBOutlet weak var leftScoreLabel: UILabel!
    @IBOutlet weak var rightScoreLabel: UILabel!

    override func viewDidLoad() {
    // Do any additional setup after loading the view, typically from a nib.


    override func didReceiveMemoryWarning() {
    // Dispose of any resources that can be recreated.

    @IBAction func DealButton(_ sender: UIButton) {
    print(“deal tapped”)


  2. Chris, I got to the point where I was testing the deal button but my simulator gives a black screen. I can’t see the cards, the button, etc. Any idea why? Also, when we added the @IBAction func DealButton automatically, the syntax was ( _sender: UIButton) but when you added it manually the syntax was (sender: UIButton). Why no “_” and space in front of sender and does it matter? Thanks. Love the tutorials.

  3. Hi! Tried the War app now that Swift 3 is released. I get an error when pushing the deal button.
    Here´s the error: 2016-09-12 12:08:55.212 War[78415:2396242] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[War.ViewController playRoundTapped:]: unrecognized selector sent to instance 0x7fd50be02d70’

    I think its something with @IBAction func playRoundTapped(sender: UIButton) but I can´t get it to work.
    It´s connected when I look in the connections inspector but when I look in theViewController.swift the circle on the left is not filled?!
    Please help!

  4. Hey Chris! I’m following along but ran into an issue once I introduced the images to the project. I can load the project with the green background and the back of the cards but when I hit “play”, the cards disappear. I had the container boxes (FirstCardImage and SecondCardImage) colored originally and they would appear when the cards went away, which leads me to believe the issue is somewhere within the constraints hierarchy? Once I returned them to their default color, the only thing that happens after I hit play is the image of the back of the card dissapears. I’ve played with it and cannot seem to fix it. Any insight you could provide would be greatly appreciated!

    • I just realized I posted this to the wrong video, as I was working backwards to see if I could solve my problem. The problem didn’t really start until a video or two later, for your reference.

      • Hey Sonny, when you click the play button and it’s changing the image for the UIImageViews, make sure that the name of the image you put in exists in your images.xcassets (asset library). I suspect it’s going blank because it’s trying to load an image that doesn’t exist!

  5. Seriously bro, loved your approach, i did most of the mistakes you have mentioned!!!! i am in the middle of tutorials I would definitely request you to further investigate on swift.

    • Hey Marco, I suspect that maybe your background imageview is the topmost element and is covering all of the other elements? In your storyboard, in the document outline on the left hand side that lists all the elements in your view, try moving your imageview closer to the top of the list (but still keeping it underneath the view)

  6. When I drag the Play Round Button to the Assistant editor, and when I put it in between the last two curly brackets, the box shows up with the options “type” and the whole Oulet and Outlet Collection thing….but there is no option for “Action” in the “Connection” tab. There is also no “Event” option. What should I do?

    • Hey 12girls, I suspect you’re accidentally dragging the constraint rather than the button element.
      It may be easier to drag the play button from the document outline to the right side rather than clicking and dragging the button in the view.

Leave a Comment