由于未捕获的异常“NSInternalInconsistencyException”错误而终止应用程序

Chr*_*ris 1 xcode ios swift

class HomeViewController: UIViewController {

    @IBOutlet weak var userNameLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Show the current visitor's username
        if let pUserName = PFUser.currentUser()?["username"] as? String {
            self.userNameLabel?.text = "@" + pUserName
        }
    }

    override func viewWillAppear(animated: Bool) {
        if (PFUser.currentUser() == nil) {
            dispatch_async(dispatch_get_main_queue(), { () -> Void in

                let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("Login")
                self.presentViewController(viewController, animated: true, completion: nil)
            })
        }

    }
    @IBAction func commentAction(sender: AnyObject) {

        self.performSegueWithIdentifier("CommentSegue", sender: self)
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        if segue.identifier == "CommentSegue"{

            let summaryView = segue.destinationViewController as? TableViewController

        }

    }

   }
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UITableViewController loadView] 从故事板“Main”实例化了标识符为“UIViewController-tCJ-qt-q4b”的视图控制器,但没有得到 UITableView。

有谁知道我该如何解决这个问题?

Phi*_*lls 5

您创建的控制器是控制器的一个UITableViewController或子类。该错误告诉您该控制器的顶级视图不是UITableView.

您需要修复故事板中视图控制器的链接,或者将控制器更改为其他类。