使用下面的代码,按下按钮时出现错误。我不确定为什么。错误是无法识别的选择器发送到实例并终止于"终止与NSException类型的未捕获异常。"任何帮助肯定表示赞赏。 感谢
class WordSearchWindow: UIViewController {
let boardsize = 10
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(false)
buttonGridder()
}
func buttonGridder() {
for x in 0..<self.boardsize {
for y in 0..<self.boardsize{
let sizer = ButtonGrid.frame.width
let buttonSize:CGFloat = sizer / CGFloat(self.boardsize)
let letterButton = WordButton(column: x, row: y, buttonSize: buttonSize, buttonMargin: 0)
letterButton.addTarget(self, action: "letterFirst", forControlEvents: .TouchDown)
letterButton.addTarget(self, action: "letterSecond", forControlEvents: .TouchUpInside)
self.ButtonGrid.addSubview(letterButton)
}
}
}
func letterFirst(sender: WordButton) {
print("hello1")
}
func letterSecond(sender: WordButton) {
print("hello2")
}
}
答案 0 :(得分:1)
试试这个:
letterButton.addTarget(self, action: "letterFirst:", forControlEvents: .TouchDown)
letterButton.addTarget(self, action: "letterSecond:", forControlEvents: .TouchUpInside)
在操作中添加: