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条回答
我只想做你的唯一
2楼-- · 2019-01-07 14:38

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

查看更多
趁早两清
3楼-- · 2019-01-07 14:42

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.

查看更多
倾城 Initia
4楼-- · 2019-01-07 14:47

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

查看更多
可以哭但决不认输i
5楼-- · 2019-01-07 14:47

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 
查看更多
迷人小祖宗
6楼-- · 2019-01-07 14:47

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.

查看更多
甜甜的少女心
7楼-- · 2019-01-07 14:50

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

查看更多
登录 后发表回答