ios - 如何在没有 Storyboard的情况下运行应用程序?

标签 ios swift xcode uitableview appdelegate

Xcode 8 和 Swift 3 的新手。非常感谢任何帮助。我一直在做尽可能多的研究,但我仍然无法在不使用 Storyboard 的情况下运行我的应用程序。由于以下原因,我在模拟器中启动它时似乎出现黑屏:

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) 在项目设置中删除“主 Storyboard”设置的 Storyboard

enter image description here

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

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

关于ios - 如何在没有 Storyboard的情况下运行应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45115354/

相关文章:

ios - 如何停止将图像保存到手机相册?

ios - 如果它是 iPhone 专用应用程序,我必须为 iPad 制作图标吗?

arrays - swift 3 : Trying to parse JSON but keep getting type issues

c++ - 释放内存问题

xcode - codesign 总是通过终端给出没有发现身份的错误

ios - 一次选择多个 UITextView

objective-c - 在 Xcode 中将 RSS 日期格式转换为德语日期

swift - 预加载场景以防止延迟?

swift - 如何在不使用 swift 的第三个的情况下交换任何类型的两个变量?

xcode - 无需用户交互即可有效自动刷新UITableview(IOS 5)