我正在尝试使用一些代码来制作使用 Xcode 7.3 和 Swift 2.2 的初学者应用程序,但我一直遇到同样的问题。我以前使用过类似的代码,但这不起作用。出现的错误消息是“预期的','分隔符”,当我修复它时,同样的消息会一次又一次地出现。我还得到“表达式列表中的预期表达式”和“调用中参数'action'的参数缺失”。它们都是由同一行引起的
button.addTarget(self, action: #selector(RatingControl.ratingButtonTapped(_:)), forControlEvents: .TouchDown)
这是代码
import UIKit
class RatingControl: UIView {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 44, height: 44))
button.backgroundColor = UIColor.redColor()
button.addTarget(self, action: #selector(RatingControl.ratingButtonTapped(_:)), forControlEvents: .TouchDown)
addSubview(button)
}
override func intrinsicContentSize() -> CGSize {
return CGSize(width: 240, height: 44)
}
func ratingButtonTapped(button: UIButton) {
print("Button pressed")
}
}