btn.addTarget(self, action:"tapped", forControlEvents:UIControlEvents.TouchDown)
2015-11-29 22:02:38.551 TextView[1753:527042] -[TextView.ViewController tapped]: unrecognized selector sent to instance 0x136ea5010
2015-11-29 22:02:38.557 TextView[1753:527042] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TextView.ViewController tapped]: unrecognized selector sent to instance 0x136ea5010'
*** First throw call stack:
(0x184aa0f48 0x199563f80 0x184aa7c5c 0x184aa4c00 0x1849a8cac 0x18a06bcfc 0x18a06bc78 0x18a053930 0x18a0743cc 0x18a06b014 0x18a063cdc 0x18a0344a4 0x18a03276c 0x184a58544 0x184a57fd8 0x184a55cd8 0x184984ca0 0x18fbc0088 0x18a09cffc 0x1000f2110 0x199db28b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
出现这个原因是由于在tapped函数里边加了一个按钮对象,如下方法所示:func tapped(button: UIButton)
{
let alert=UIAlertController()
alert.title="sxj"
alert.message="哈哈"
self.presentViewController(alert, animated: true, completion: nil)
print("哈哈")
}
第一种方法是在tapped前要加上冒号,如下代码所示:func tapped()
{
let alert=UIAlertController()
alert.title="sxj"
alert.message="哈哈"
self.presentViewController(alert, animated: true, completion: nil)
print("哈哈")
}