Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

ios - UISwipeGestureRecognizer throw unrecognised selector sent error

I am getting unrecognized selector sent error in my iOS application. I tried solving the issue based on the answers mentioned in other similar thread but failed. Please have a look at the code below and help me with this.

Thanks

class ThirdViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.



        let leftSwipe = UISwipeGestureRecognizer(target: self, action:  Selector(("HandleSwipes:")))

        let rightSwipe = UISwipeGestureRecognizer(target: self, action:   Selector(("HandleSwipes:")))

        leftSwipe.direction = .left
        rightSwipe.direction = .right


        view.addGestureRecognizer(leftSwipe)
        view.addGestureRecognizer(rightSwipe)



    }



    func HandleSwipes(sender: UISwipeGestureRecognizer) {

        //if(sender.direction == .left)
        //{
        //    tabBarController?.selectedIndex = 1
        //}
    }
}
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Write selector like this.

Swift 2.3 or lower.

let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(HandleSwipes(_:)))
let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(HandleSwipes(_:)))

Swift 3

let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(HandleSwipes(sender:)))
let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(HandleSwipes(sender:)))

Note: One suggestion it is batter method name always start with lower case not upper case. So it is batter if you use handleSwipes instead of HandleSwipes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...