【问题标题】:How to run app without storyboard?如何在没有情节提要的情况下运行应用程序?
【发布时间】:2017-07-15 06:48:02
【问题描述】:

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

}

【问题讨论】:

    标签: ios swift xcode uitableview appdelegate


    【解决方案1】:

    1) 在项目设置中删除“主情节提要”设置的情节提要

    2) 您的代码中有错字。视图控制器类名为 ViewController,但您实例化了 ViewContoller(缺少“r”)。

    完成这两件事后,您的代码对我来说运行良好并且项目运行良好:

    【讨论】:

    • 如果他在代码中也有错字,它应该不会编译。
    • @vivek,你是对的。我只是想指出我必须更改哪些内容才能使示例正常运行。
    【解决方案2】:

    Check General>Deployment Info> 主界面仍然指向 Main.storyboard?如果是,请删除它。

    【讨论】:

    • 谢谢你,维韦克。已经在 via general>Deployment Info 中删除了“main”。原来我没有删除文件夹中的 Main.storyboard 文件。
    猜你喜欢
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    • 2020-10-19
    • 1970-01-01
    • 2017-01-16
    相关资源
    最近更新 更多