Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nib but didn't get a UITableView

Tags:

ios

ios6

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.

like image 436
irmu Avatar asked Jun 27 '12 08:06

irmu


5 Answers

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.

like image 129
mattjgalloway Avatar answered Nov 02 '22 20:11

mattjgalloway


I had a similar problem using storyboards. I'll post my solution for the benefit of others. The key is that if you have correctly set the file's owner to the subclass of UITableView you still have to make sure the view property is set to the Table View. I'm using storyboards, but the same sort of thing should apply to nibs as well. Expand the "document outline" so you can see the hierarchy of your storyboard. I will include some screen shots below. The quick way to solve this is that you want to look at your view in the document outline. Delete any tableview you have as a child of it. Drag the other tableview on top of the view property. Done. I'll show you in screen shots.

enter image description here

Notice the two tables. You want to remove table1 and its cell.

enter image description here

Good. Now drag table2 to the view and you're done. Should work now. Basically if you have a subclass of UITableViewController then it must have Table View in place of view or it will crash.

enter image description here

like image 29
smileBot Avatar answered Nov 02 '22 22:11

smileBot


The reason might be :

.h file check that it is a subclass of UIViewController. it will solve the problem.

like image 17
Abdul Yasin Avatar answered Nov 02 '22 22:11

Abdul Yasin


In short, you are setting a custom UITableViewController subclass to a UIViewController !! You cannot do this. You should give the UIViewController a UIViewController subclass.

like image 12
oabarca Avatar answered Nov 02 '22 22:11

oabarca


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
like image 12
saneryee Avatar answered Nov 02 '22 22:11

saneryee