nib but didn't get a UITableView

2019-01-07 14:34发布

My application works for iOS 5.1 but for iOS 6 simulator I get the following error.

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "MainListViewController" nib but didn't get a UITableView.'

I am subclassing UITableViewController and I don't want to change it.

The tableview is created programmatically, there is a dummy MainListViewController.xib to load from Mainwindow.xib Tab Bar Controller.

I also tried to delete MainListViewController.xib, remove it from the MainWindow.xib Tab Bar Controller, created the MainListViewController in AppDelegate and added it to Tab Bar Controller as UITabBarItem to get rid of this nib problem, but I still get the same error.

标签: ios ios6
13条回答
Rolldiameter
2楼-- · 2019-01-07 14:58

I find the solution when using Storyboards and 1 table View.

The key is when you create a custom class (newViewController) just check that is a subclass of UITableViewController. Once created Go to the table view controller (of our table) and in the Identity Inspector select the custom class that just created before (newViewController).

That works for me. Hope my comment help someone.

查看更多
成全新的幸福
3楼-- · 2019-01-07 14:59

If you use UITableView as your Top View.

Like this :

enter image description here

You need use UITableViewController in your Controller

class ItemsViewController: UITableViewController

If you use UITableView under a View in your Storyboatd.

Like this :

enter image description here

You need use UITableViewDelegate and UITableViewDataSource with UIViewController

class ItemsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
查看更多
疯言疯语
4楼-- · 2019-01-07 15:01

@smileBot answer helped me realized the solution is very easy and the error raised by iOS makes sense

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "MainListViewController" nib but didn't get a UITableView.'

Their basically saying that nib's view controller is not returning a UITableView because it isn't, for most - your nib is returning a View - which is created for you by default when you create a new ViewController in the Xcode IDE.

The solution is as simple as deleting that View - which might feel against the norm - but go ahead and select it and backspace - then drag and drop a UITableView inside your ViewController and this UITableView will now act as your root view inside your TableViewController.

Keep in mind this is only necessary for classes directly subclassing UITableViewController.

Good luck.

查看更多
成全新的幸福
5楼-- · 2019-01-07 15:03

Please connect your table view as a View outlet.outlet must be hooked up to a UITableView.

查看更多
Juvenile、少年°
6楼-- · 2019-01-07 15:03

I had this problem and solving it was just one simple thing.

Keep the nib if you already created ...

Go to (XIB file) and add a tableView component from objects library to the XIB file's iPhone screen, and it should work :)

查看更多
戒情不戒烟
7楼-- · 2019-01-07 15:04

If you have a NIB for the UITableViewController subclass then its view outlet must be hooked up to a UITableView.

You're right to delete MainListViewController.xib and do it all in code, but the reason it didn't work for you is because the old XIB will not be deleted when you build & run. So, delete the app from the simulator and try again. It should work then.

查看更多
登录 后发表回答