RootViewController 上的 NSInternalInconsistencyException
我正在尝试创建一个导航类型的应用程序,但我想自定义初始视图,以便表格视图不占据整个框架,而是嵌入子视图中,以便我可以在该应用程序首次启动。
我在 RootViewController.h
中声明了 UIView
和 UITableView
ivars,并将它们添加为具有标准“(nonatomic, keep) 的属性” IBOutlet
" 令牌;在 RootViewController.m
中,我合成了两者,并在 viewDidUnload
中添加了将它们设置为 nil
的代码,并在 dealloc 中释放了它们
。 (努力成为一个良好的内存管理公民。)我没有添加任何其他代码。编译时没有警告。当我尝试测试该应用程序时,它立即(并且反复)崩溃,并显示以下消息:
*** Terminating app due to uncaught exception
NSInternalInconsistencyException',
reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the
"RootViewController" nib but the view outlet was not set.'
我已将视图和表视图连接到我的 RootViewController 笔尖中的文件所有者;当我右键单击对象图中的文件所有者时,我看到它们都列为出口。当我右键单击每个控件时,我会看到“文件所有者”作为引用出口。
帮助!我该如何解决这个问题?
更新
//
// RootViewController.m
// rx2
//
#import "RootViewController.h"
@implementation RootViewController
/* I added these two lines */
@synthesize uiView;
@synthesize uiTableView;
#pragma mark -
#pragma mark View lifecycle
#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 0;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
/* I added these two lines */
self.uiView = nil;
self.uiTableView = nil;
}
- (void)dealloc {
/* I added these two lines */
[uiView release];
[uiTableView release];
[super dealloc];
}
@end
I'm trying to create a navigation-stype app, but I want to customize the initial view so that the tableview doesn't occupy the entire frame, but rather is embedded within a sub-view so I can some labels and an image when the app is first launched.
I declared UIView
and UITableView
ivars in RootViewController.h
, and added them both as properties with the standard "(nonatomic, retain) IBOutlet
" tokens; and in RootViewController.m
, I synthesized both, and added code to set them to nil
in viewDidUnload
, and released them in dealloc
. (Trying to be a good memory-management citizen.) I haven't added any other code. No warnings on the compile. When I tried to test-drive the app, it crashed immediately (and repeatedly) with the message:
*** Terminating app due to uncaught exception
NSInternalInconsistencyException',
reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the
"RootViewController" nib but the view outlet was not set.'
I have connected both the view and the tableview to the File's Owner in my RootViewController
nib; when I right-click on File's Owner in the object graph, I see both of them listed as Outlets. When I right-click each control, I see File's Owner as the Referencing Outlet.
Help! How do I fix this?
Update
//
// RootViewController.m
// rx2
//
#import "RootViewController.h"
@implementation RootViewController
/* I added these two lines */
@synthesize uiView;
@synthesize uiTableView;
#pragma mark -
#pragma mark View lifecycle
#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 0;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
/* I added these two lines */
self.uiView = nil;
self.uiTableView = nil;
}
- (void)dealloc {
/* I added these two lines */
[uiView release];
[uiTableView release];
[super dealloc];
}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这意味着 RootViewController 的
view
属性(继承自UIViewController
)未连接到 nib 文件中的视图。如果右键单击对象图中的文件所有者,您会看到它的view
出口连接到布局中的视图,如所附屏幕截图所示?您可以将 RootViewController.h 文件作为对您问题的编辑来发布吗?
What this means is that the RootViewController's
view
property (inherited fromUIViewController
) isn't connected to a view in the nib file. If you right click the File's Owner in the object graph, so you see it'sview
outlet connected to a view in the layout as in the attached screenshot?Can you post your RootViewController.h file as an edit to your question?
您只需将 xib 中的默认视图连接到文件所有者即可。
you just need to connect the default view in xib to the file owner.