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
312 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 Reply

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.


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

...