“Unrecognized selector sent to instance” in swift

后端 未结 10 505
刺人心
刺人心 2020-12-10 10:36

I have no idea what I am doing wrong. I am also quite new to programming so I am not very good at debugging. This was a test app so that I can see how swift ties in with app

10条回答
  •  不思量自难忘°
    2020-12-10 11:14

    In your viewDidLoad, notice my Selector is calling my func with the colon.

    override func viewDidLoad() {
            super.viewDidLoad()
            // init gesture recognizer swipe right vars
            var rightSwipe = UISwipeGestureRecognizer(target: self, action: Selector("gestureFunc:"))
            rightSwipe.direction = UISwipeGestureRecognizerDirection.Right
            view.addGestureRecognizer(rightSwipe) 
        }
    

    Then make sure that the Selector i.e. func is ready to receive it's swipe:

            // selector from UISwipeGestureRecognizer
            func nextWeapon(gesture: UISwipeGestureRecognizer) {
            println("swipe right")
            }
    

提交回复
热议问题