I'm going through Apple's iOS development with Swift tutorial and have gotten myself stuck on the 5th stage:
import UIKit
class RatingControl: UIStackView {
// MARK: Initialisation
override init(frame: CGRect) {
super.init(frame: frame)
setupButtons()
}
required init(coder: NSCoder) {
super.init(coder: coder)
setupButtons()
}
// MARK: Button action
@objc func ratingButtonTapped(button: UIButton) {
NSLog("Button pressed")
}
// MARK: Private methods
private func setupButtons() {
NSLog("setupButtons() called")
// Create the button
let button = UIButton()
button.backgroundColor = UIColor.red
// Add constraints
button.translatesAutoresizingMaskIntoConstraints = false
button.heightAnchor.constraint(equalToConstant: 44.0).isActive = true
button.widthAnchor.constraint(equalToConstant: 44.0).isActive = true
// Setup the button action
button.addTarget(self, action: #selector(RatingControl.ratingButtonTapped(button:)), for: .touchUpInside)
// Add the button to the stack
addArrangedSubview(button)
}
}
setupButtons
is called and I see the message in Xcode's debug console, and the button appears as a red box on the simulator:
However, when I click on the button, nothing happens - no message is printed to the debug console.
I honestly have no clue how I would even begin debugging this, since everything compiles/runs without errors, and I've already tried placing debug messages around what seems to be the issue.
Does anyone have any ideas on what's going on?
EDIT: Here is where the class is being used, and the output in the console: