如何在没有故事板的情况下运行app?

时间:2017-07-15 06:48:03

标签: ios swift xcode uitableview appdelegate

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()

}

2 个答案:

答案 0 :(得分:2)

1)在项目设置中,删除“主要故事板”设置的故事板

enter image description here

2)您的代码中存在拼写错误。 View控制器类名为ViewController,但是您实例化了ViewContoller(错过了'r')。

执行这两项操作后,您的代码对我和项目运行都很有效: enter image description here

答案 1 :(得分:1)

检查常规&gt;部署信息&gt;主界面仍然指向Main.storyboard?如果是,请删除它。