Hi all,

I've been trying to follow the basic Apple developer tutorial, where you create a food tracker app.

I can not get one part of the code to work, and I can't see why. Not only is it exactly the same as in the example, but searches online also seem to enforce that I've done this right...

I create 5 UIButton objects with this code:

    // MARK: Initilisation
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        for _ in 0..<5 {
            let button = UIButton(frame: CGRect(x: 0, y: 0, width: 44, height: 44))
            button.backgroundColor = UIColor.redColor()
            button.addTarget(self, action: "ratingButtonTapped:", forControlEvents: .TouchDown)
            ratingButtons += [button]

As per the button.addTarget, I then have the function below:

    // MARK: Button Action

    func ratingButtonTapped(button: UIButton) {
        print("Button pressed 
2 Years
Discussion Span
Last Post by James_43

Ah, silly mistake. No problem with the code, the issue was to do with StackView. Another object was obstructing it, so it wasn't registering the touch action!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.