[英]NSInternalInconsistencyException on RootViewController
我正在嘗試創建一個navigation-stype應用程序,但我想自定義初始視圖,以便tableview不占用整個框架,而是嵌入在子視圖中,所以我可以在一些標簽和圖像時該應用程序首次推出。
我在RootViewController.h
聲明了UIView
和UITableView
ivars,並將它們作為屬性添加到標准“ (nonatomic, retain) 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.'
我已將視圖和tableview連接到RootViewController
nib中的File所有者; 當我在對象圖中右鍵單擊File's Owner時,我看到它們都被列為Outlets。 當我右鍵單擊每個控件時,我將File's Owner視為Referencing Outlet。
救命! 我該如何解決?
更新
//
// 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
出口連接到布局中的視圖,如附帶的屏幕截圖所示?
你可以發布你的RootViewController.h文件作為你的問題的編輯?
您只需要將xib中的默認視圖連接到文件所有者。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.