简体   繁体   English

Swift:向上滑动时出错

[英]Swift : Error when swiping up

I kept on getting these errors when I try do a swipe up gesture. 当我尝试向上滑动手势时,我不断遇到这些错误。 Swiping "right" is alright but "up" would throw errors. 轻扫“正确”是可以的,但“向上”则会引发错误。

Any help would be great. 任何帮助都会很棒。

Thanks in advance. 提前致谢。

2015-12-24 14:53:36.977 Swipes & Shake[58213:9895793] -[Swipes___Shake.ViewController swiped]: unrecognized selector sent to instance 0x7fc549ea4400 2015-12-24 14:53:36.977滑动和摇动[58213:9895793]-[Swipes ___ Shake.ViewController swiped]:无法识别的选择器已发送到实例0x7fc549ea4400

2015-12-24 14:53:36.982 Swipes & Shake[58213:9895793] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Swipes___Shake.ViewController swiped]: unrecognized selector sent to instance 0x7fc549ea4400' 2015-12-24 14:53:36.982滑动和震动[58213:9895793] ***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[Swipes ___ Shake.ViewController swiped]:无法识别的选择器已发送至实例0x7fc549ea4400'

libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) libc ++ abi.dylib:以类型为NSException(lldb)的未捕获异常终止

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    var swipeRight = UISwipeGestureRecognizer(target: self, action: "swiped:")
    swipeRight.direction = UISwipeGestureRecognizerDirection.Right
    self.view.addGestureRecognizer(swipeRight)

    var swipeUp = UISwipeGestureRecognizer(target: self, action: "swiped")
    swipeUp.direction = UISwipeGestureRecognizerDirection.Up
    self.view.addGestureRecognizer(swipeUp)
    }

func swiped(gesture: UIGestureRecognizer)
{
    if let swipeGesture =  gesture as? UISwipeGestureRecognizer
    {
        switch swipeGesture.direction
        {
        case UISwipeGestureRecognizerDirection.Right:
            print("RIGHT")
        case UISwipeGestureRecognizerDirection.Up:
            print("UP")
        default:
            break
        }
    }
}

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


}

You have missed : after swiped in var swipeUp = UISwipeGestureRecognizer(target: self, action: "swiped") 您错过了: swipedvar swipeUp = UISwipeGestureRecognizer(target: self, action: "swiped")

Correct is var swipeUp = UISwipeGestureRecognizer(target: self, action: "swiped:") 正确的方法是var swipeUp = UISwipeGestureRecognizer(target: self, action: "swiped:")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM