gpt4 book ai didi

ios - UISwipeGestureRecognizer 抛出无法识别的选择器发送错误

转载 作者:搜寻专家 更新时间:2023-11-01 05:53:19 24 4
gpt4 key购买 nike

我的 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(_:)))

swift 3

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

注意:一个建议是 batter 方法名称总是以小写而不是大写开头。因此,如果您使用 handleSwipes 而不是 HandleSwipes 会更好。

关于ios - UISwipeGestureRecognizer 抛出无法识别的选择器发送错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39586525/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com