2015-11-12 36 views
0

我已经得到了class Menu: SKScene,那么func touchesBegan它里面,给了我的错误:与:“withEvent :)的touchesBegan(从超类方法法的冲突 - 覆盖给出错误

方法Objective-C的选择 '的touchesBegan:withEvent:方法' 与方法冲突 '的touchesBegan(:withEvent :)' 从超类的UIResponder'具有相同的目标C选择

无论如何,如果在我的前添加超控功能说:

方法不覆盖任何超类中的方法。

任何想法?整个代码:

import SpriteKit 

class Menu: SKScene { 




var title : SKLabelNode? 
var start : SKLabelNode? 

override func didMoveToView(view: SKView) { 

    backgroundColor = SKColor.whiteColor() 

    self.title = SKLabelNode(fontNamed: "Chalkduster") 
    self.start = SKLabelNode(fontNamed: "Chalkduster") 

    self.title!.name = "title" 
    self.start!.name = "new" 


    self.addChild(self.title!) 
    self.addChild(self.start!) 
} 

    func touchesBegan(touches: NSSet, withEvent even: UIEvent) { 

     self.menuHelper(touches) 
    } 

    func menuHelper(touches: NSSet) { 
     for touch in touches { 
      let nodeAtTouch = self.nodeAtPoint(touch.locationInNode(self)) 
      if nodeAtTouch.name == "title" { 
       print("Title pressed") 
      } 
      else if nodeAtTouch.name == "new" { 
       print("Start pressed") 
      } 
     } 

    } 

回答

2

签名(从文档)此方法是...

func touchesBegan(_ touches: Set<UITouch>, withEvent event: UIEvent?) 

touchesSet(不NSSetUITouch对象和event是一个可选UIEvent

您还需要重写它...

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 
    self.menuHelper(touches) 
} 
+0

非常感谢您!仍在学习基础知识。 – ffritz

相关问题