gpt4 book ai didi

swift - 快速向左滑动手势时出现无法识别的选择器错误

转载 作者:行者123 更新时间:2023-11-28 08:08:29 25 4
gpt4 key购买 nike

我正在尝试创建一个简单的 swift left segue 到下一个 View Controller ,但是我收到了一个无法识别的选择器错误。这是代码失败:

   override func viewDidLoad() {
super.viewDidLoad()

//below creates the instances for swiping to change screens
//only added right here because it's the main screen

var swipeLeft : UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipe:"))
swipeLeft.direction = UISwipeGestureRecognizerDirection.Left

self.view.addGestureRecognizer(swipeLeft)

func swipe(Sender: UISwipeGestureRecognizer!) {
print("swiped left")
let vc = self.storyboard!.instantiateViewControllerWithIdentifier("OnDeck") as! OnDeck
self.presentViewController(vc, animated: true, completion: nil)
}
}

这是我遇到的错误:

2017-06-07 19:07:00.990 Test[65722:3911717] -[Test.GameView swipe:]: unrecognized selector sent to instance 0x7fc2d310f700
2017-06-07 19:07:01.000 Test[65722:3911717] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Test.GameView swipe:]: unrecognized selector sent to instance 0x7fc2d310f700'

最佳答案

对于 Swift 3,选择器应如下所示:

#selector(swipe(Sender:))

您可以使用#selector 表示法进行编译时检查。

对于 Swift 2,选择器将是:

#selector(swipe(_:))

关于swift - 快速向左滑动手势时出现无法识别的选择器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44424162/

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