我正在尝试创建一个导航类型的应用程序,但我想自定义初始 View ,以便 tableview 不会占据整个框架,而是嵌入到一个 subview 中,这样我就可以添加一些标签和应用程序首次启动时的图像。
我在 RootViewController.h
中声明了 UIView
和 UITableView
变量,并使用标准“(nonatomic , 保留) IBOutlet
" token ;在 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.'
我已将 View 和 TableView 连接到我的 RootViewController
nib 中的文件所有者;当我在对象图中右键单击 File's Owner 时,我看到它们都列为 Outlets。当我右键单击每个控件时,我看到文件所有者作为引用导出。
帮助!我该如何解决这个问题?
更新
//
// 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
最佳答案
这意味着 RootViewController 的 view
属性(继承自 UIViewController
)未连接到 nib 文件中的 View 。如果您右键单击对象图中的文件所有者,您会看到它的 view
导出连接到布局中的 View ,如所附屏幕截图所示?
您可以发布您的 RootViewController.h 文件作为对您问题的编辑吗?
关于ios - RootViewController 上的 NSInternalInconsistencyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5418869/