【发布时间】:2011-03-24 12:10:26
【问题描述】:
我正在尝试创建一个导航类型的应用程序,但我想自定义初始视图,以便表格视图不会占据整个框架,而是嵌入在子视图中,这样我就可以添加一些标签和应用首次启动时的图像。
我在RootViewController.h 中声明了UIView 和UITableView 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