【发布时间】:2014-06-15 06:56:56
【问题描述】:
我有按钮和方法
switchViewButton = UIButton.buttonWithType(.System) as? UIButton
switchViewButton!.frame = CGRectMake(15, 25, 50, 50)
switchViewButton!.setTitle("sss", forState: .Normal)
switchViewButton!.addTarget(self, action: "switchViewFunc", forControlEvents: .TouchUpInside)
switchViewButton!.backgroundColor = UIColor.redColor()
switchViewButton!.layer.cornerRadius = 25
topView.addSubview(switchViewButton)
@IBAction func switchViewFunc(sender : AnyObject){
println("Button was clicked", sender)}
此方法使应用程序崩溃,原因是“无法识别的选择器已发送到实例”
我有另一个按钮和方法,就像这样,它工作得很好。如果我删除 (sender : AnyObject) 它可以工作。我不明白怎么回事
【问题讨论】:
-
为什么在手动将 IBAction 添加为目标时使用它? IBAction 专门用于挂钩 IB 中的东西。您可以将其定义为常规函数。