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]
            addSubview(button)
        }
    }

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

    // MARK: Button Action

    func ratingButtonTapped(button: UIButton) {
        print("Button pressed 

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.