gpt4 book ai didi

swift - UIGestureRecognizer 导致未捕获的异常错误

转载 作者:行者123 更新时间:2023-11-30 12:55:40 24 4
gpt4 key购买 nike

UIGestureRecognizer 导致未捕获的异常错误。它说无法识别的选择器发送到实例。我正在使用 Swift 3 和 Xcode 8。

这是代码。

import UIKit
import UIKit.UIGestureRecognizer

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

print("starting")

var swipeDown = UISwipeGestureRecognizer(target: self, action:
"respondToSwipeGesture:")
swipeDown.direction = UISwipeGestureRecognizerDirection.down
self.view.addGestureRecognizer(swipeDown)

}

func respondToSwipeGesture(gesture: UIGestureRecognizer) {

if let swipeGesture = gesture as? UISwipeGestureRecognizer {

switch swipeGesture.direction {

case UISwipeGestureRecognizerDirection.down:

// go to View Controller 2


gopage2()

default:
print("does it work? ")
break
}
}
}





func gopage2() {


let storyboard=UIStoryboard(name: "Main", bundle: nil)
let viewController =
storyboard.instantiateViewController(withIdentifier: "ViewController2")
as! UIViewController
self.present(viewController, animated: true) }


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}





}

respondToSwipeGesture 是否需要成为公共(public)类?

最佳答案

只需在参数中添加“忽略此”下划线即可。

func respondToSwipeGesture(_ gesture: UIGestureRecognizer) {

关于swift - UIGestureRecognizer 导致未捕获的异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40428968/

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