2017-07-15 89 views
0

新的Xcode 8和Swift 3.任何幫助將不勝感激。我一直在做盡可能多的研究,但是我仍然無法在不使用故事板的情況下運行我的應用程序。看來我得到一個黑色屏幕,當我在模擬器中啓動它,因爲:如何在沒有故事板的情況下運行應用程序?

Terminating app due to uncaught exception 
'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </User...........................app> (loaded)' with name '`main`'' 
*** First throw call stack: 
(
    0 CoreFoundation      0x0000000104099b0b __exceptionPreprocess + 171 
    1 libobjc.A.dylib      0x0000000101379141 objc_exception_throw + 48 
    2 CoreFoundation      0x0000000104102625 +[NSException raise:format:] + 197 
    3 UIKit        0x0000000102676e74 -[UINib instantiateWithOwner:options:] + 501 
    4 UIKit        0x0000000102679614 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 222 
    5 UIKit        0x000000010226f7ea -[UIApplication _loadMainNibFileNamed:bundle:] + 75 
    6 UIKit        0x000000010226fe13 -[UIApplication _loadMainInterfaceFile] + 260 
    7 UIKit        0x000000010226e4b6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1407 
    8 UIKit        0x000000010226b7f3 -[UIApplication workspaceDidEndTransaction:] + 182 
    9 FrontBoardServices     0x00000001057845f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24 
    10 FrontBoardServices     0x000000010578446d -[FBSSerialQueue _performNext] + 186 
    11 FrontBoardServices     0x00000001057847f6 -[FBSSerialQueue _performNextFromRunLoopSource] + 45 
    12 CoreFoundation      0x000000010403fc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    13 CoreFoundation      0x00000001040250cf __CFRunLoopDoSources0 + 527 
    14 CoreFoundation      0x00000001040245ff __CFRunLoopRun + 911 
    15 CoreFoundation      0x0000000104024016 CFRunLoopRunSpecific + 406 
    16 UIKit        0x000000010226a08f -[UIApplication _run] + 468 
    17 UIKit        0x0000000102270134 UIApplicationMain + 159 
    18 testappfour       0x0000000100da2c57 main + 55 
    19 libdyld.dylib      0x000000010501b65d start + 1 
    20 ???         0x0000000000000001 0x0 + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

AppDelegate.swift

import UIKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
     // Override point for customization after application launch. 
     window = UIWindow(frame: UIScreen.main.bounds) 
     window?.makeKeyAndVisible() 

     window?.rootViewController = UINavigationController(rootViewController: ViewController()) 
     return true 
    } 

ViewController.swift

import UIKit 

class ViewController: UIViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

} 

回答

1

檢查常規>部署信息>主界面仍然指向Main.storyboard?如果是刪除它。

+0

謝謝你,維韋克。已通過通用>部署信息刪除「main」。原來我沒有刪除我的文件夾中的Main.storyboard文件。 – Jeff

2

1)在項目設置中刪除故事板的 '主要故事板' 設置

enter image description here

2)。在你的代碼中的錯字。視圖控制器類被命名爲ViewController,但實例化ViewContoller('r'被忽略)。

做的兩件事你的代碼很適合我和項目運行後: enter image description here

+0

如果他在代碼中輸入錯誤,它也不應該編譯。 – vivek

+0

@vivek,你是對的。我只想指出我爲了使這個例子工作而必須改變的。 – RomanN

相關問題