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.
任何帮助都会很棒.
谢谢.
2015-12-24 14:53:36.977轻扫&摇动[58213:9895793]-[刷卡___ Shake.ViewController扫过]:无法识别的选择器已发送到实例0x7fc549ea4400
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.982轻扫& Shake [58213:9895793] ***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[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'
libc ++ abi.dylib:以类型为NSException的未捕获异常终止 (lldb)
libc++abi.dylib: terminating with uncaught exception of type 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.
}
}
推荐答案
您在var swipeUp = UISwipeGestureRecognizer(target: self, action: "swiped")
正确是var swipeUp = UISwipeGestureRecognizer(target: self, action: "swiped:")
这篇关于Swift:向上滑动时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!