在我的viewDidLoad函数中,我设置了一个滑动手势识别器:
var swipeRecognizer:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("move"))
swipeRecognizer.direction = .Right
view.addGestureRecognizer(swipeRecognizer)然后我设置了移动函数:
func move(swipe:UISwipeGestureRecognizer) {
NSLog("swiped")
}但是,当我正确地滑动时,我仍然会得到以下错误:
[_TtC8swiftris9GameScene move]: unrecognized selector sent to instance 0xc81c200
2014-06-03 14:52:57.560 swiftris[45440:6777826]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[_TtC8swiftris9GameScene move]: unrecognized selector sent to instance 0xc81c200'有什么问题吗?
发布于 2014-06-03 20:00:51
您将函数定义为move(swipe:UISwipeGestureRecognizer),它映射到obj-c方法名move:,但选择器只是"move"。您需要使用"move:"代替。
发布于 2014-06-03 20:06:16
正如@Kevin正确地指出的,您的选择器与您的方法不匹配,这解释了“未识别的选择器”异常。但是,我认为值得注意的是,您可以完全放弃转换到Selector,并使用字符串文字代替它。
可以使用字符串文字构造选择器,例如let mySelector: selector = "tappedButton:“。因为字符串文本可以自动转换为选择器,所以可以将字符串文字传递给接受选择器的任何方法。
示例:
let gesture: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action:"move:")https://stackoverflow.com/questions/24023811
复制相似问题