Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

ios - UISwipeGesture 'unrecognized selector sent to instance'

If someone could please help me resolve this issue, would be great! I have spent a few hours trying to fix, with no luck

Error...

2016-06-23 20:30:43.341057 Scaling Rings[408:38903] [DYMTLInitPlatform] platform initialization successful 2016-06-23 20:30:43.750822 Scaling Rings[408:38776] Metal GPU Frame Capture Enabled 2016-06-23 20:30:43.751531 Scaling Rings[408:38776] Metal API Validation Enabled 2016-06-23 20:30:48.293661 Scaling Rings[408:38776] -[Scaling_Rings.MenuScene slide:]: unrecognized selector sent to instance 0x145e1c410 2016-06-23 20:30:48.299061 Scaling Rings[408:38776] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Scaling_Rings.MenuScene slide:]: unrecognized selector sent to instance 0x145e1c410' * First throw call stack: (0x190ad9980 0x1900d44bc 0x190ae0778 0x190add6e0 0x1909de61c 0x196e13754 0x196e16e5c 0x1969f6b3c 0x196894900 0x196e0747c 0x196e07100 0x196e06338 0x196892a24 0x1968638c8 0x19701efd4 0x19701941c 0x190a8a3f0 0x190a89cc8 0x190a87938 0x1909ba2e4 0x19239315c 0x1968ce6fc 0x1968c9438 0x1000a1d44 0x19055c600) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

Code...

import Foundation
import SpriteKit

var startRing = SKShapeNode()

class MenuScene: SKScene {

    func slide(sender: AnyObject){
        debugPrint("WORKS")
    }

    override func didMove(to view: SKView) {

        let upSwipe = UISwipeGestureRecognizer(target: self, action: Selector("slide:"))
        upSwipe.direction = .up
        view.addGestureRecognizer(upSwipe)

    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to change your selector declaration to #selector(slide) and add an underscore before your method parameter func slide(_ sender: UISwipeGestureRecognizer):

class GameScene: SKScene {

    @objc func slide(_ sender: UISwipeGestureRecognizer){
        print("WORKS")
    }
    override func didMove(to view: SKView) {
        let upSwipe = UISwipeGestureRecognizer(target: self, action: #selector(slide))
        upSwipe.direction = .up
        view.addGestureRecognizer(upSwipe)
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...