ios - RootViewController 上的 NSInternalInconsistencyException

标签 ios navigation tableview

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

我在 RootViewController.h 中声明了 UIViewUITableView 变量,并使用标准“(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 ,如所附屏幕截图所示?

the file's owner's view property connected to a view

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

关于ios - RootViewController 上的 NSInternalInconsistencyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5418869/

相关文章:

ios - 以编程方式设置 WKPickerItem 不会超过某个值?

ios - 为什么 Xcode 停止提供文本预测?

CSS固定位置导航,在页面底部滑开

html - 如何添加下拉子菜单

ios - 无法快速使用 CGImageCreateWithImageInRect 裁剪触摸位置

ios - 使用 UIPanGestureRecognizer 计算轻弹后 UIView 的最终位置

react-native - 检查是否设置了导航状态参数对象

java - 有什么方法可以迭代打印(或在一秒后)tableView(javaFX)中的表记录

iOS - 在滚动之前移动 TableView

ios - TableView 手势识别器影响滑动删除行