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:向上滑动时出错的主要内容,如果未能解决你的问题,请参考以下文章

向上滚动 UITable 后的 Swift 5 调用函数

React - 向下滚动时向上滑动固定导航栏,向上滚动时向下滑动

iOS Swift ScrollView、UITableView、滚动区域

Swift:添加子视图时视图的框架发生变化

h5向上滑动效果 最后一页向上滑动时底部显示第一张怎么回事

将向上滑动手势识别器添加到模态视图