我试图将目标添加到 UIButton 并偶然发现了一个奇怪的行为
如果我尝试:
//h = a collection view header
switch myVar {
case "none":
h.button.addTarget(self, action: "buttonTapped:", forControlEvents: .TouchUpInside)
func buttonTapped(sender:AnyObject) {
sendFriendRequest(self.targetUser,nil
}
}
我得到 SIGABRT - “找不到选择器”
但是如果我将函数移出开关盒并使其成为我的 ViewController 的方法,一切都会按预期工作。
有人对此有解释吗?是不允许还是有技术原因?