ios 笔尖但没有得到 UITableView
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11221802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nib but didn't get a UITableView
提问by irmu
My application works for iOS 5.1 but for iOS 6 simulator I get the following error.
我的应用程序适用于 iOS 5.1,但对于 iOS 6 模拟器,我收到以下错误。
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "MainListViewController" nib but didn't get a UITableView.'
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-[UITableViewController loadView] 加载了“MainListViewController”笔尖但没有获得 UITableView。
I am subclassing UITableViewController
and I don't want to change it.
我正在继承UITableViewController
,我不想改变它。
The tableview is created programmatically, there is a dummy MainListViewController.xib
to load from Mainwindow.xib
Tab Bar Controller.
tableview 以编程方式创建,有一个虚拟对象MainListViewController.xib
可以从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.
我还尝试删除MainListViewController.xib
,将其从MainWindow.xib
Tab Bar Controller 中删除,MainListViewController
在 AppDelegate 中创建并将其添加到 Tab Bar ControllerUITabBarItem
以摆脱这个笔尖问题,但我仍然遇到相同的错误。
回答by mattjgalloway
If you have a NIB for the UITableViewController
subclass then its view
outlet mustbe hooked up to a UITableView
.
如果你有一个UITableViewController
子类的 NIB,那么它的view
出口必须连接到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.
删除MainListViewController.xib
并在代码中完成所有操作是正确的,但它对您不起作用的原因是因为在构建和运行时旧的 XIB 不会被删除。因此,从模拟器中删除该应用程序并重试。它应该工作。
回答by smileBot
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 viewin 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.
我在使用故事板时遇到了类似的问题。为了他人的利益,我将发布我的解决方案。关键是,如果您已将文件的所有者正确设置为 UITableView 的子类,您仍然必须确保将视图属性设置为表视图。我正在使用故事板,但同样的事情也应该适用于笔尖。展开“文档大纲”,以便您可以看到故事板的层次结构。我将在下面包含一些屏幕截图。解决此问题的快速方法是您希望在文档大纲中查看您的视图。删除您作为它的孩子的任何 tableview。将另一个 tableview 拖到 view 属性的顶部。完毕。我将在屏幕截图中向您展示。
Notice the two tables. You want to remove table1 and its cell.
注意这两个表。您想删除 table1 及其单元格。
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.
好的。现在将 table2 拖到视图中,您就完成了。现在应该工作。基本上,如果您有 UITableViewController 的子类,那么它必须有 Table View 代替视图,否则它会崩溃。
回答by Abdul Yasin
The reason might be :
原因可能是:
.h file check that it is a subclass of UIViewController. it will solve the problem.
.h 文件检查它是否是 UIViewController 的子类。它将解决问题。
回答by saneryee
If you use UITableView as your Top View.
如果您使用 UITableView 作为您的顶视图。
Like this :
像这样 :
You need use UITableViewController in your Controller
您需要在控制器中使用 UITableViewController
class ItemsViewController: UITableViewController
If you use UITableView under a View in your Storyboatd.
如果您在 Storyboatd 的视图下使用 UITableView。
Like this :
像这样 :
You need use UITableViewDelegate and UITableViewDataSource with UIViewController
您需要将 UITableViewDelegate 和 UITableViewDataSource 与 UIViewController 一起使用
class ItemsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
回答by oabarca
In short, you are setting a custom UITableViewController subclass to a UIViewController !! You cannot do this. You should give the UIViewController a UIViewController subclass.
简而言之,您正在将自定义 UITableViewController 子类设置为 UIViewController !你不可以做这个。你应该给 UIViewController 一个 UIViewController 子类。
回答by chadenis
I find the solution when using Storyboards and 1 table View.
我在使用 Storyboards 和 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).
关键是当您创建自定义类 (newViewController) 时,只需检查它是否是 UITableViewController 的子类。创建后转到表视图控制器(我们的表)并在身份检查器中选择之前刚刚创建的自定义类(newViewController)。
That works for me. Hope my comment help someone.
这对我行得通。希望我的评论对某人有所帮助。
回答by Joe Barbour
There is several reason why this may occur.
发生这种情况的原因有多种。
You may have not have added UITableViewDelegate & UITableViewDataSource to your .h
@interface TableController : UIViewController {
You may have not connected your declared outlets to the components in the Storyboard/Nib
You maybe calling a UIViewController instead of a UITableView or vide verser in your .h
您可能还没有将 UITableViewDelegate & UITableViewDataSource 添加到您的 .h
@interface 表控制器:UIViewController {
您可能尚未将声明的插座连接到 Storyboard/Nib 中的组件
您可能在 .h 中调用 UIViewController 而不是 UITableView 或视频
@interface TableController : UIViewController
@interface TableController : UIViewController
or
或者
@interface TableController : UITableViewController
回答by Sanjay Kumar Yadav
Please connect your table view as a View outlet.outlet must be hooked up to a UITableView.
请将您的表格视图连接为 View outlet.outlet 必须连接到 UITableView。
回答by DevTorch
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 :)
转到(XIB 文件)并将对象库中的 tableView 组件添加到 XIB 文件的 iPhone 屏幕,它应该可以工作:)
回答by uplearnedu.com
This worked for me. Hope it helps you.
这对我有用。希望对你有帮助。
In AppDelegate-->
在 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:
确保在情节提要中您的视图控制器指向此类: