UISwipeGesture'无法识别的选择器发送到实例' [英] UISwipeGesture 'unrecognized selector sent to instance'
问题描述
如果有人可以帮我解决这个问题,那就太好了!我花了几个小时试图修复,没有运气
错误...
2016-06-23 20:30:43.341057 Scaling Rings [408:38903] [DYMTLInitPlatform]平台初始化成功
2016-06-23 20:30:43.750822 Scaling Rings [408:38776] Metal GPU帧捕获已启用
2016-06-23 20:30:43.751531缩放环[408:38776]金属API验证已启用
2016-06-23 20:30:48.293661缩放环[408:38776] - [Scaling_Rings.MenuScene slide:]:无法识别的选择器发送到实例0x145e1c410
2016-06-23 20:30:48.299061缩放环[408:38776] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [Scaling_Rings.MenuScene slide:]:无法识别的选择器发送到实例0x145e1c410'
* 第一次抛出调用堆栈:
(0x190ad9980 0x1900d44bc 0x190ae0778 0x190add6e0 0x1909de61c 0x196e13754 0x196e16e5c 0x1969f6b3c 0x196894900 0x196e0747c 0x196e07100 0x196e06338 0x196892a2 4 0x1968638c8 0x19701efd4 0x19701941c 0x190a8a3f0 0x190a89cc8 0x190a87938 0x1909ba2e4 0x19239315c 0x1968ce6fc 0x1968c9438 0x1000a1d44 0x19055c600)
libc ++ abi.dylib:以NSException类型的未捕获异常终止
(lldb)
代码......
import Foundation
import SpriteKit
var startRing = SKShapeNode()
class MenuScene:SKScene {
func slide(sender:AnyObject){
debugPrint(WORKS) )
}
覆盖func didMove(查看:SKView){
let upSwipe = UISwipeGestureRecognizer(target:self,action:Selector(slide:)) )
upSwipe.direction = .up
view.addGestureRecognizer(upSwipe)
}
}
您需要将选择器声明更改为 #selector(slide)
并在方法参数 fu之前添加下划线nc slide(_ sender:UISwipeGestureRecognizer)
:
class GameScene:SKScene {
func slide(_ sender:UISwipeGestureRecognizer){
print(WORKS)
}
覆盖func didMove(查看:SKView){
let upSwipe = UISwipeGestureRecognizer( target:self,action:#selector(slide))
upSwipe.direction = .up
view.addGestureRecognizer(upSwipe)
}
}
If someone could please help me resolve this issue, would be great! I have spent a few hours trying to fix, with no luck
Error...
2016-06-23 20:30:43.341057 Scaling Rings[408:38903] [DYMTLInitPlatform] platform initialization successful 2016-06-23 20:30:43.750822 Scaling Rings[408:38776] Metal GPU Frame Capture Enabled 2016-06-23 20:30:43.751531 Scaling Rings[408:38776] Metal API Validation Enabled 2016-06-23 20:30:48.293661 Scaling Rings[408:38776] -[Scaling_Rings.MenuScene slide:]: unrecognized selector sent to instance 0x145e1c410 2016-06-23 20:30:48.299061 Scaling Rings[408:38776] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Scaling_Rings.MenuScene slide:]: unrecognized selector sent to instance 0x145e1c410' * First throw call stack: (0x190ad9980 0x1900d44bc 0x190ae0778 0x190add6e0 0x1909de61c 0x196e13754 0x196e16e5c 0x1969f6b3c 0x196894900 0x196e0747c 0x196e07100 0x196e06338 0x196892a24 0x1968638c8 0x19701efd4 0x19701941c 0x190a8a3f0 0x190a89cc8 0x190a87938 0x1909ba2e4 0x19239315c 0x1968ce6fc 0x1968c9438 0x1000a1d44 0x19055c600) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
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'无法识别的选择器发送到实例'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!