我試圖在斯威夫特使用以下UIGesture識別器崩潰應用
let recognizer = UISwipeGestureRecognizer(target: self, action: "handleSwipe:")
recognizer.direction = UISwipeGestureRecognizerDirection.Right
self.view?.addGestureRecognizer(recognizer)
func handleSwipe() {
println("Swiped Right")
但是,一旦我運行一個UI手勢識別器添加到我的SKScene並進行刷卡,應用程序崩潰與以下日誌:
2014-11-22 23:21:35.251革命[83866:460316] - [Revolution.levelSelect handleSwipe:]:無法識別的選擇器發送到實例0x7feec842b920 2014-11-22 23:21:35.255革命[83866:460316 ] ***由於未捕獲的異常'NSInvalidArgumentException',原因:' - [Revolution.levelSelect handleSwipe:]:無法識別的select或發送到實例0x7feec842b920'
的libC++ abi.dylib:與類型NSException
的未捕獲的異常終止請問有什麼需要添加到GameViewController或者怎麼樣的選擇是導致其崩潰?
它仍然無法運行。我有一種感覺,它與GameViewController有關。 UIGesturerecognizer是否應該在那裏初始化? – 2014-11-23 05:10:55
不,你應該在GameScene.m的'didMoveToView'中初始化它。在'didMoveToView'中也聲明瞭'handleSwipe()'嗎?我無法從你的帖子中看出來。 – 0x141E 2014-11-23 05:14:10
它是。 '讓識別= UISwipeGestureRecognizer(目標:自,動作: 「handleSwipe:」) recognizer.direction = UISwipeGestureRecognizerDirection.Right self.view .addGestureRecognizer(識別) FUNC handleSwipe(手勢:UISwipeGestureRecognizer){ 的println( 「向右滑動」) }' – 2014-11-23 05:17:55