gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:58:46 28 4
gpt4 key购买 nike

我在 iOS 应用程序中收到无法识别的选择器发送错误。我尝试根据其他类似线程中提到的答案解决该问题,但失败了。请看一下下面的代码并帮助我解决这个问题。

谢谢

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,效果会更好。

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

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