2014-10-26 81 views
1

我在嘗試啓動我的應用程序時遇到此錯誤。我的應用應該只是一個空的SKScene。根據我的理解,這通常是由於沒有導入適當的框架造成的。我已經連接了我的UIKit和SpriteKit框架,而這些是我使用的唯一兩個框架。無法實例化名爲SCNView的類

以下是我的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 

回答

1

看起來你打錯一個故事板中的類名。確保故事板和xib文件中所有自定義類的名稱都是正確的。

+2

經過進一步調查我的問題是,我的視圖是一個SCNView!創建我的遊戲時,我沒有勾選SpriteKit框,它默認爲SceneKit。 – 2014-10-26 22:43:22

5

我有同樣的問題,當我的項目模板是Single View Application。因爲Xcode不自動添加SceneKit.framework。你必須手動添加它。

相關問題