UISwipeGestureRecognizer抛出无法识别的选择器发送错误 [英] UISwipeGestureRecognizer throw unrecognised selector sent error
本文介绍了UISwipeGestureRecognizer抛出无法识别的选择器发送错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的iOS应用程序中出现无法识别的选择器
错误。我尝试根据其他类似线程中提到的答案解决问题,但失败了。请看下面的代码,并帮助我。
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:)))
注意:一个建议是电池方法名称始终以小写字母而不是大写字母开头。因此,如果您使用 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屋!
查看全文