UISwipeGestureRecognizer 抛出无法识别的选择器发送错误 [英] UISwipeGestureRecognizer throw unrecognised selector sent error

查看:17
本文介绍了UISwipeGestureRecognizer 抛出无法识别的选择器发送错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 iOS 应用程序中收到 unrecognized selector sent 错误.我尝试根据其他类似线程中提到的答案解决该问题,但失败了.请查看下面的代码并帮助我解决这个问题.

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.

谢谢

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
        //}
    }
}

推荐答案

像这样编写选择器.

Swift 2.3 或更低版本.

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:)))

注意: 一个建议是,batter 方法名称总是以小写而不是大写开头.因此,如果您使用 handleSwipes 而不是 HandleSwipes,那就太棒了.

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.

这篇关于UISwipeGestureRecognizer 抛出无法识别的选择器发送错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆