在我的viewDidLoad函数中,我设置了一个滑动手势识别器: var swipeRecognizer:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("move"))swipeRecognizer.direction = .Rightview.addGestureRecogni
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'
可能是什么问题呢?
您将函数定义为move(swipe:UISwipeGestureRecognizer),它映射到obj-c方法名称move:,但您的选择器只是“移动”.你需要使用“move:”代替.