RootViewController上的NSInternalInconsistencyExceptionException [英] NSInternalInconsistencyException on RootViewController

查看:97
本文介绍了RootViewController上的NSInternalInconsistencyExceptionException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个导航类型的应用程序,但我想自定义初始视图,以使tableview不会占据整个框架,而是嵌入到一个子视图中,这样我就可以添加一些标签和首次启动该应用程序时的图片.

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.

我在RootViewController.h中声明了UIViewUITableView ivars,并将它们都添加为带有标准"(nonatomic, retain) IBOutlet"标记的属性.在RootViewController.m中,我合成了两者,并添加了代码以在viewDidUnload中将它们设置为nil,然后在dealloc中发布了它们. (试图成为一个好的内存管理公民.)我没有添加任何其他代码.编译时无警告.当我尝试测试该应用程序时,它立即(并反复)崩溃,并显示以下消息:

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.'

我已经在我的RootViewController笔尖中将视图和表视图都连接到了文件的所有者;当我在对象图中右键单击文件的所有者"时,我看到它们都被列为出口".右键单击每个控件时,我将文件的所有者视为引用出口.

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.

帮助!我该如何解决?

更新

//
//  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插座已连接到布局中的视图,如所附的屏幕截图所示?

What this means is that the RootViewController's view property (inherited from UIViewController) 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's view outlet connected to a view in the layout as in the attached screenshot?

您可以张贴RootViewController.h文件作为对问题的编辑吗?

Can you post your RootViewController.h file as an edit to your question?

这篇关于RootViewController上的NSInternalInconsistencyExceptionException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆