我似乎无法让NSTimer在我创建的课程中工作。每次我运行应用程序时,它都会崩溃并说下面的内容:
2015-11-06 19:23:47.108项目[30546:7771747] *** NSForwarding:警告:类的对象0x7b025190' Project.LogoScreen'没有实现methodSignatureForSelector: - 提前麻烦 无法识别的选择器 - [Project.LogoScreen show] (lldb)
但是,当我在GameScene中使用NSTimers时,我没有收到任何错误。
以下是我正在运行的代码失败:
// Class #1
import SpriteKit
var background: SKSpriteNode!
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
anchorPoint = CGPointMake(0.5, 0.5)
background = SKSpriteNode(color: UIColor.whiteColor(), size: size)
addChild(background)
LogoScreen().create()
}
}
// Class #2
import Foundation
import SpriteKit
var spriteLogo: SKSpriteNode!
var spriteScreenLogo: SKSpriteNode!
class LogoScreen {
func create() {
spriteScreenLogo = SKSpriteNode(color: UIColor.blackColor(), size: background.size)
spriteScreenLogo.zPosition = 1
background.addChild(spriteScreenLogo)
spriteLogo = SKSpriteNode(imageNamed: "logo")
spriteLogo.alpha = 0
spriteLogo.zPosition = 2
background.addChild(spriteLogo)
NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: Selector("show"), userInfo: nil, repeats: false)
}
func show() {
print("here")
}
}
答案 0 :(得分:1)
像这样:
@objc func show() {
print("here")
}