【问题标题】:NSInternalInconsistencyException on RootViewControllerRootViewController 上的 NSInternalInconsistencyException
【发布时间】:2011-03-24 12:10:26
【问题描述】:

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

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

我已将视图和表格视图都连接到我的RootViewController nib 中的文件所有者;当我在对象图中右键单击 File's Owner 时,我看到它们都列为 Outlets。当我右键单击每个控件时,我会看到 File's Owner 作为引用出口。

帮助!我该如何解决这个问题?

更新

//
//  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

【问题讨论】:

  • 我将您的答案合并到您的问题中,您可能需要编辑前言。请不要将回复作为答案发布,并考虑接受社区给您的建议:)
  • 我将回复作为答案发布,因为我无法发布回复。我得到的建议是什么?我已经检查并重新检查了 nib 文件,并且所有属性都连接到 File's Owner。那么解决这个问题的下一步是什么?

标签: ios navigation tableview


【解决方案1】:

这意味着 RootViewController 的 view 属性(继承自 UIViewController)未连接到 nib 文件中的视图。如果您在对象图中右键单击文件的所有者,那么您会看到它的 view 插座连接到布局中的视图,如随附的屏幕截图所示?

您能否发布您的 RootViewController.h 文件作为对您问题的编辑?

【讨论】:

  • 是的,我看到的连接如下:
  • File's Owner 列出了我的实例变量属性以及视图属性的 Outlets;他们都填上了圆圈。(对不起,我似乎不能像你那样剪切和粘贴图像)......
  • 您是如何在此页面上嵌入文件所有者图形的?我拍了一张快照(command+shift+3 / 4),但我不能插入它...
  • cmets 不支持图像......好吧,这里有一个断开连接的地方,如果没有看到您的项目文件就很难判断。您可以在您的问题中发布您的 RootViewController 的 m 文件吗?
  • 您可以在问题中添加图片。文本编辑框上方有一个小宝丽来图标,可让您这样做。我会发布它的屏幕截图,但是……
【解决方案2】:

您只需要将 xib 中的默认视图连接到文件所有者即可。

【讨论】:

  • 查看RootViewController.xib文件中的File's Owner时,outlet的圆圈被填上了
  • 查看视图是否已连接,如果已连接则断开连接并重新连接
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-06
相关资源
最近更新 更多