starting ios project without storyboard

前端 未结 9 1233
渐次进展
渐次进展 2021-01-12 23:28

Im having some troubles to start an iOS app using xibs instead of storyboard. The problem is that im getting a black screen and the first view controller is not being called

相关标签:
9条回答
  • 2021-01-12 23:58

    This is a kind of "out of the box" solution, so it is irrelevant to your code. Specially since I don't see anything wrong with your code.

    I had the same problem and tried for a long time to fix the code, what worked for me was finding an example project (in github for example) that uses xibs.

    Download it and then edit it to make your application it is guaranteed to work. It is a shame that Xcode wants to force us to use their storyboards with these kinds of problems.

    0 讨论(0)
  • 2021-01-13 00:00

    In Swift 3.0

    //MARK: Initial View Controller
    func initialViewController(){
        self.window = UIWindow(frame: UIScreen.main.bounds)
        let rootViewController = UIViewController(nibName: "HomeVC", bundle: nil)
        let navigation : UINavigationController = UINavigationController(rootViewController: rootViewController)
        navigation.isNavigationBarHidden = true
        self.window?.rootViewController = navigation
        self.window?.makeKeyAndVisible()
    }
    

    in appdelegate.swift

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
        initialViewController()
    
        return true
    }
    
    0 讨论(0)
  • 2021-01-13 00:05

    In xCode 11:

    Step1:

    -> Delete the storyBoard file

    Step2:

    Under yourProject > General > deployment info > main interface -> delete reference to storyboard

    Step 3:

    In info.plist > Application Scene Manifest > Scene Configuration > Application Session Role > item 0 > storyboard name

    -> Delete the line

    Step 4:

    In SceneDelegate.m

     - (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
    
              self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
              self.window.windowScene = (UIWindowScene *)scene;
              self.window.rootViewController = [[UINavigationController alloc] 
                                   initWithRootViewController:ViewController.new];
              [self.window makeKeyAndVisible];
    
    }  
    

    make sure to import your viewController headfile like so: #import "ViewController.h"

    0 讨论(0)
提交回复
热议问题