UIGestureRecognizer 导致未捕获的异常错误

UIGestureRecognizer causes uncaught exception error

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 class?

只需在参数中添加一个 "ignore this" 下划线即可。

func respondToSwipeGesture(_ gesture: UIGestureRecognizer) {