繁体   English   中英

RootViewController上的NSInternalInconsistencyException

[英]NSInternalInconsistencyException on RootViewController

我正在尝试创建一个navigation-stype应用程序,但我想自定义初始视图,以便tableview不占用整个框架,而是嵌入在子视图中,所以我可以在一些标签和图像时该应用程序首次推出。

我在RootViewController.h声明了UIViewUITableView 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM