gpt4 book ai didi

ios - 无法实例化名为 SCNView 的类

转载 作者:搜寻专家 更新时间:2023-11-01 05:48:12 26 4
gpt4 key购买 nike

当我尝试启动我的应用程序时遇到此错误。我的应用程序应该只是一个空的 SKScene View 。据我了解,这通常是由于未导入正确的框架造成的。我已经链接了我的 UIKit 和 SpriteKit 框架,这是我正在使用的仅有的两个框架。

以下是我的 ViewController 代码:

import UIKit
import SpriteKit

class GameViewController: UIViewController {

var scene: GameScene!


override func viewDidLoad() {
super.viewDidLoad()

// Configure the view
let skView = view as SKView
skView.multipleTouchEnabled = false

//Create and configure the scene
scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .AspectFill

// Present the scene.
skView.presentScene(scene)

}

override func prefersStatusBarHidden() -> Bool {
return true
}


override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Release any cached data, images, etc that aren't in use.
}

}

以下是我的 GameScene 代码:

import UIKit
import SpriteKit



let HurdleSize:CGFloat = 20.0
let TickLengthLevelOne = NSTimeInterval(600)

class GameScene: SKScene {
var tick: (() -> ())?
var tickLengthMillis = TickLengthLevelOne
var lastTick:NSDate?

var textureCache = Dictionary<String, SKTexture>()

override init(size: CGSize) {
super.init(size: size)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

下面是我的错误跟踪:

  Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named SCNView'
*** First throw call stack:
(
0 CoreFoundation 0x0161d946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01e1ca97 objc_exception_throw + 44
2 CoreFoundation 0x0161d86d +[NSException raise:format:] + 141
3 UIKit 0x007bfd74 UINibDecoderDecodeObjectForValue + 317
4 UIKit 0x007bfc2f -[UINibDecoder decodeObjectForKey:] + 371
5 UIKit 0x00629bf1 -[UIRuntimeConnection initWithCoder:] + 189
6 UIKit 0x007bff1a UINibDecoderDecodeObjectForValue + 739
7 UIKit 0x007c011c UINibDecoderDecodeObjectForValue + 1253
8 UIKit 0x007bfc2f -[UINibDecoder decodeObjectForKey:] + 371
9 UIKit 0x00628ea7 -[UINib instantiateWithOwner:options:] + 1164
10 UIKit 0x0044b624 -[UIViewController _loadViewFromNibNamed:bundle:] + 270
11 UIKit 0x0044bdbb -[UIViewController loadView] + 295
12 UIKit 0x0044bfef -[UIViewController loadViewIfRequired] + 78
13 UIKit 0x0044c595 -[UIViewController view] + 35
14 UIKit 0x00343825 -[UIWindow addRootViewControllerViewIfPossible] + 66
15 UIKit 0x00343c99 -[UIWindow _setHidden:forced:] + 287
16 UIKit 0x00343f50 -[UIWindow _orderFrontWithoutMakingKey] + 49
17 UIKit 0x0035228d -[UIWindow makeKeyAndVisible] + 80
18 UIKit 0x002ef776 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3108
19 UIKit 0x002f2c0d -[UIApplication _runWithMainScene:transitionContext:completion:] + 1639
20 UIKit 0x0030b7d0 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke + 59
21 UIKit 0x002f181f -[UIApplication workspaceDidEndTransaction:] + 155
22 FrontBoardServices 0x0745f9de __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
23 FrontBoardServices 0x0745f46f __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
24 FrontBoardServices 0x07471425 __31-[FBSSerialQueue performAsync:]_block_invoke + 26
25 CoreFoundation 0x015411c0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
26 CoreFoundation 0x01536ad3 __CFRunLoopDoBlocks + 195
27 CoreFoundation 0x0153692b __CFRunLoopRun + 2715
28 CoreFoundation 0x01535bcb CFRunLoopRunSpecific + 443
29 CoreFoundation 0x015359fb CFRunLoopRunInMode + 123
30 UIKit 0x002f11e4 -[UIApplication _run] + 571
31 UIKit 0x002f48b6 UIApplicationMain + 1526
32 HurdleJumpr 0x000a88cf main + 111
33 libdyld.dylib 0x03cbfac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

最佳答案

我有同样的问题,当我的项目模板是Single View Application时。因为Xcode不会自动添加SceneKit.framework。您必须手动添加它。

关于ios - 无法实例化名为 SCNView 的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26576837/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com