2017-07-15 1 views
0

Nouveau sur Xcode 8 et Swift 3. Toute aide serait grandement appréciée. J'ai fait autant de recherches que possible, mais j'ai toujours du mal à utiliser mon application sans utiliser le storyboard. Il semble que je reçois un écran noir quand je le lance dans le simulateur en raison de:Comment lancer l'application sans 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() 

} 

Répondre

1

Vérification générale> Informations sur le déploiement> Main Interface pointe toujours vers Main.storyboard? Si oui, retirez-le.

+0

Merci, Vivek. Déjà supprimé "principal" dans la via général> Informations de déploiement. Il s'avère que je n'ai pas supprimé le fichier Main.storyboard dans mon dossier. – Jeff

2

1) Dans les paramètres du projet supprimer storyboard pour réglage 'principal Storyboard'

enter image description here

2) Il y a une faute de frappe dans votre code. La classe View Controller est nommée ViewController mais vous instanciez ViewContoller ('r' est manqué).

Après avoir fait ces deux choses que votre code fonctionne bien pour moi et projet se poursuivra: enter image description here

+0

Il ne devrait pas compiler s'il a fait une faute de frappe dans le code aussi. – vivek

+0

@vivek, vous avez raison. Je voulais juste préciser ce que je devais exactement changer pour que l'exemple fonctionne. – RomanN