Swift:向上滑动时出错
Posted
技术标签:
【中文标题】Swift:向上滑动时出错【英文标题】:Swift : Error when swiping up 【发布时间】:2015-12-24 07:01:29 【问题描述】:当我尝试向上滑动手势时,我不断收到这些错误。 “向右”滑动没问题,但“向上”滑动会引发错误。
任何帮助都会很棒。
提前致谢。
2015-12-24 14:53:36.977 滑动和摇动[58213:9895793] -[Swipes___Shake.ViewController 滑动]:无法识别的选择器发送到实例 0x7fc549ea4400
2015-12-24 14:53:36.982 Swipes & Shake[58213:9895793] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[Swipes___Shake.ViewController 刷卡]:无法识别的选择器发送到实例0x7fc549ea4400'
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.
【问题讨论】:
【参考方案1】:您在var swipeUp = UISwipeGestureRecognizer(target: self, action: "swiped")
中的swiped
之后错过了:
正确的是var swipeUp = UISwipeGestureRecognizer(target: self, action: "swiped:")
【讨论】:
非常感谢。我根本没有注意到它以上是关于Swift:向上滑动时出错的主要内容,如果未能解决你的问题,请参考以下文章
React - 向下滚动时向上滑动固定导航栏,向上滚动时向下滑动