Search code examples
swiftuitableviewnibrootviewcontroller

TableViewcontroller.xib created by me should be initial controller


I have created TableViewController by xib not on storyboard. I have view controller which loads by default. Now I want that TableViewController as root controller. Thanks in advance.


Solution

  • You can do like this.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {        
        window = UIWindow(frame: UIScreen.main.bounds)  
        let navigationController: UINavigationController = UINavigationController(rootViewController: YourViewController()) //where YourViewController is name of viewController which you want to use as rootViewController
        self.window?.rootViewController = navigationController
        self.window?.makeKeyAndVisible()
        return true
    }