我正在尝试使用一些代码来制作一个使用 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")
}
}
最佳答案
您需要清理项目。
按 Shift + ⌘ + K
关于ios - "Expected expression in list of expressions",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36165674/