我得到unrecognized selector sent我的iOS应用程序错误。我尝试根据其他类似主题中提到的答案解决问题,但失败了。请查看下面的代码,并为此提供帮助。
unrecognized selector sent
谢谢
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(_:)))
迅捷3
let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(HandleSwipes(sender:))) let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(HandleSwipes(sender:)))
注意: 一种建议是面糊方法名称始终以小写而不是大写开头。因此,如果您使用handleSwipes而不是,那就更糟了HandleSwipes。
handleSwipes
HandleSwipes