nib but didn't get a UITableView

IosIos6

Ios Problem Overview


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 Solutions


Solution 1 - Ios

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.

Solution 2 - Ios

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

Solution 3 - Ios

The reason might be :

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

Solution 4 - Ios

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

Solution 5 - Ios

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

Solution 6 - Ios

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.

Solution 7 - Ios

There is several reason why this may occur.

  1. You may have not have added UITableViewDelegate & UITableViewDataSource to your .h

    @interface TableController : UIViewController {

  2. You may have not connected your declared outlets to the components in the Storyboard/Nib

  3. You maybe calling a UIViewController instead of a UITableView or vide verser in your .h

@interface TableController : UIViewController

or

 @interface TableController : UITableViewController 

Solution 8 - Ios

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

Solution 9 - Ios

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 :)

Solution 10 - Ios

@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.

Solution 11 - Ios

This worked for me. Hope it helps you.

In AppDelegate-->

#import "TableViewController.h" // name of your TableViewController class

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//PUT
TableViewController *controller = [[TableViewController alloc]
                                  initWithStyle:UITableViewStylePlain];
    self.window = [[UIWindow alloc]
                   initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = controller;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    // Override point for customization after application launch.
    return YES;
}

Make sure in storyboard your view controller points to this class:

Story Board

Solution 12 - Ios

I also encountered this problem, but I used storyboard in xcode 6.2. I deleted the corresponding view from storyboard and re-dragged the table view controller from the object library to storyboard, then it works.

Solution 13 - Ios

I have same problem and after waste 3 hours i find it out..."this is mistake" i use tableviewcontroller class and give uiviewcontroller reference of this class, instead of view controller class i take tableviewcontroller class as i take uiviewcontroller in storyboard. so delete tableviewcontroller class and paste your code of tableviewcontroller class to view controller class,"not paste whole code only paste logic" after this in storyboard in identity inspector give class reference of current view controller class.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionirmuView Question on Stackoverflow
Solution 1 - IosmattjgallowayView Answer on Stackoverflow
Solution 2 - IossmileBotView Answer on Stackoverflow
Solution 3 - IosAbdul YasinView Answer on Stackoverflow
Solution 4 - IosoabarcaView Answer on Stackoverflow
Solution 5 - IossaneryeeView Answer on Stackoverflow
Solution 6 - IoschadenisView Answer on Stackoverflow
Solution 7 - IosJoe BarbourView Answer on Stackoverflow
Solution 8 - IosSanjay Kumar YadavView Answer on Stackoverflow
Solution 9 - IosDevTorchView Answer on Stackoverflow
Solution 10 - IosRyhanView Answer on Stackoverflow
Solution 11 - Iosuplearned.comView Answer on Stackoverflow
Solution 12 - IosMengjieView Answer on Stackoverflow
Solution 13 - Ioskanisht sahlotView Answer on Stackoverflow