RootViewController 上的 NSInternalInconsistencyException

发布于 2024-10-26 00:27:50 字数 3142 浏览 1 评论 0原文

我正在尝试创建一个导航类型的应用程序,但我想自定义初始视图,以便表格视图不占据整个框架,而是嵌入子视图中,以便我可以在该应用程序首次启动。

我在 RootViewController.h 中声明了 UIViewUITableView ivars,并将它们添加为具有标准“(nonatomic, keep) 的属性” 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 笔尖中的文件所有者;当我右键单击对象图中的文件所有者时,我看到它们都列为出口。当我右键单击每个控件时,我会看到“文件所有者”作为引用出口。

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

更新

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

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.

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

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.

Help! How do I fix this?

Update

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾北清歌寒 2024-11-02 00:27:50

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

连接到视图的文件所有者的视图属性

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

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?

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

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

自找没趣 2024-11-02 00:27:50

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

you just need to connect the default view in xib to the file owner.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文