无法识别的选择器发送到实例

无法识别的选择器发送到实例

本文介绍了UISwipeGesture'无法识别的选择器发送到实例'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人可以帮我解决这个问题,那就太好了!我花了几个小时试图修复,没有运气



错误...



Code...

import Foundation
import SpriteKit

var startRing = SKShapeNode()

class MenuScene: SKScene {

    func slide(sender: AnyObject){
        debugPrint("WORKS")
    }

    override func didMove(to view: SKView) {

        let upSwipe = UISwipeGestureRecognizer(target: self, action: Selector("slide:"))
        upSwipe.direction = .up
        view.addGestureRecognizer(upSwipe)

    }

}
解决方案

You need to change your selector declaration to #selector(slide) and add an underscore before your method parameter func slide(_ sender: UISwipeGestureRecognizer):

class GameScene: SKScene {

    func slide(_ sender: UISwipeGestureRecognizer){
        print("WORKS")
    }
    override func didMove(to view: SKView) {
        let upSwipe = UISwipeGestureRecognizer(target: self, action: #selector(slide))
        upSwipe.direction = .up
        view.addGestureRecognizer(upSwipe)
    }
}

这篇关于UISwipeGesture'无法识别的选择器发送到实例'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-23 18:03