终止应用程序由于未捕获的异常 'NSInternalInconsistencyException' 错误
问题描述:
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
}
}
}
我得到的错误是:终止应用程序由于未捕获的异常 'NSInternalInconsistencyException' 错误
终止应用程序由于未捕获的异常 'NSInternalInconsistencyException',原因是:“ - [UITableViewController中 的loadView]实例化视图控制器从标题为“Main”的标识符 “UIViewController-tCJ-qt-q4b”,但未获得 UITableView。
任何人都知道我可以解决这个问题吗?
答
您创建的控制器是一个UITableViewController
或一个子类。错误告诉你,该控制器的顶层视图不是UITableView
。
您需要修复故事板中的视图控制器链接,或者将控制器更改为其他类。
我删除了TableViewDelegate子类,并试图将commentAction按钮连接到tableview,我仍然收到错误。 – Chris
您的评论听起来不像您提出的建议。我并不感到惊讶,你仍然得到错误。 –