BRDroid
BRDroid

Reputation: 4388

How to fix from storyboard "Main", but didn't get a UITableView.' xcode

I am very new to iOS programming. I am running a simple app from a tutorial and when i try to run it on Simulator(iPhone 11) it gives me following error message

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] instantiated view controller with identifier "UIViewController-BYZ-38-t0r" from storyboard "Main", but didn't get a UITableView.'

AppDeligate

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        window = UIWindow(frame: UIScreen.main.bounds)
        window?.makeKeyAndVisible()
        let viewController = ViewController()
        window?.rootViewController = UINavigationController(rootViewController: viewController)

        return true
    }

    // MARK: UISceneSession Lifecycle
    @available(iOS 13.0, *)
    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    @available(iOS 13.0, *)
    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }


}

ViewController.swift

import UIKit

class ViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Logout", style: .plain, target: self, action: #selector(handleLogout))
    }

    @objc
    func handleLogout() {
        let loginController = LoginController()
        self.navigationController?.pushViewController(loginController, animated: true)
    }
}

And this is how my Main.Storyboard looks like

How can I fix this please, I looked online but as I am totally new to iOS world I am unable to fix it.

Thanks R

screenshot

Upvotes: 0

Views: 1571

Answers (3)

Apps Maven
Apps Maven

Reputation: 1420

Replace the view controller you see on the main storyboard with a UITableviewcontroller. Just Drag and drop the table view controller and make it as initial view controller.

Then add a UItableviewcontroller class into your project. Name the scene UITableview controller the same as the table view controller class name. And don’t forget to connect all the outlets with the view controller class. Attach the storyboard scene with the class name using the sidebar given on the right side in the Custom Class column. enter image description here 

Upvotes: 1

Anil Kumar
Anil Kumar

Reputation: 1984

try to fix this here:

inplace : class ViewController: UITableViewController {

use : class ViewController: UIViewController {

Upvotes: 0

Shehata Gamal
Shehata Gamal

Reputation: 100543

The crash means you use a usual vc not a tableVC , you must drag this ( hit command + shift + l )

enter image description here

With this look

enter image description here

Upvotes: 0

Related Questions