【发布时间】:2015-07-31 02:31:48
【问题描述】:
我想在 Swift 中使用 sender 参数将目标添加到多个按钮,但我遇到了问题
这是我的代码
var index = 10
var btn = [UIButton]()
for var i = 0; i<=index; i++
{
btn.append(UIButton(frame : ... ))
btn[i].addTarget(self, action: "event_clicked", forControlEvents: UIControlEvents.TouchUpInside)
}
func event_clicked(sender : UIButton!)
{
sender.backgroundColor = UIColor.whiteColor()
}
它运行良好,但是当我按下其中一个按钮时,会显示错误“libc++abi.dylib:以 NSException 类型的未捕获异常终止”。请帮我解决这个问题。
【问题讨论】:
标签: iphone swift uibutton target