为什么我不能用gestureTapRecogniser调用我的函数

我有这个简单的function,当有人点击屏幕时,函数内的代码执行,我知道函数中的代码有效,键入时我没有错误。

func reload(gestureRecognizer: UITapGestureRecognizer) { let skView = self.view! skView.presentScene(scene) } 

我有这个if语句,并且所有代码都工作,除非我在某个事件发生后运行该函数。 在我尝试调用’reload()’的行中,我收到错误’使用未解析的标识符重新加载’。 你能告诉我我做错了吗? 谢谢!

  if score[0] >= 10 { pauseGame() let textLabel = SKLabelNode(fontNamed: "Helvetica") textLabel.fontSize = 30 textLabel.fontColor = SKColor.white textLabel.position = CGPoint(x: 20, y: 20) textLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center textLabel.text = "HELLO" addChild(textLabel) reload() } else if score [1] >= 10 { pauseGame() sleep(5) let textLabel = SKLabelNode(fontNamed: "ChalkboardSE-Bold") textLabel.fontSize = 30 textLabel.fontColor = SKColor.white textLabel.position = CGPoint(x: 20, y: 20) textLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center textLabel.text = "HELLO" addChild(textLabel) reload() } 

只是改变

 reload() 

 reload(gestureRecognizer: nil) 

reload方法参数应该是UITapGestureRecognizer? 可选的。

 func reload(gestureRecognizer: UITapGestureRecognizer?) { let skView = self.view! skView.presentScene(scene) } 

另一个简短的方法是

更改使用UITapGestureRecognizer声明的操作方法

 ...action: #selector(self.reload())... 

意味着删除(_:)不需要做任何事情只需调用reload()函数。