[英]NSInternalInconsistencyException on RootViewController
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. 我正在尝试创建一个navigation-stype应用程序,但我想自定义初始视图,以便tableview不占用整个框架,而是嵌入在子视图中,所以我可以在一些标签和图像时该应用程序首次推出。
I declared UIView
and UITableView
ivars in RootViewController.h
, and added them both as properties with the standard " (nonatomic, retain) IBOutlet
" tokens; 我在
RootViewController.h
声明了UIView
和UITableView
ivars,并将它们作为属性添加到标准“ (nonatomic, retain) IBOutlet
”标记中; and in RootViewController.m
, I synthesized both, and added code to set them to nil
in viewDidUnload
, and released them in dealloc
. 在
RootViewController.m
,我合成了两个,并在viewDidUnload
添加了将它们设置为nil
代码,并在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; 我已将视图和tableview连接到
RootViewController
nib中的File所有者; when I right-click on File's Owner in the object graph, I see both of them listed as Outlets. 当我在对象图中右键单击File's Owner时,我看到它们都被列为Outlets。 When I right-click each control, I see File's Owner as the Referencing Outlet.
当我右键单击每个控件时,我将File's Owner视为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
What this means is that the RootViewController's view
property (inherited from UIViewController
) isn't connected to a view in the nib file. 这意味着RootViewController的
view
属性(继承自UIViewController
)未连接到nib文件中的视图。 If you right click the File's Owner in the object graph, so you see it's view
outlet connected to a view in the layout as in the attached screenshot? 如果右键单击对象图中的文件所有者,那么您会看到它的
view
出口连接到布局中的视图,如附带的屏幕截图所示?
Can you post your RootViewController.h file as an edit to your question? 你可以发布你的RootViewController.h文件作为你的问题的编辑?
您只需要将xib中的默认视图连接到文件所有者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.