iphone-UIViewController标题视图错误
因此,请给出一点背景: 我有一个应用程序具有UITableViewController-ContactDetailViewController 在顶部的这个视图中,我需要一些标签和按钮,后面是一个组样式的表视图。 所以我创建了一个包含这些元素的nib文件。ContactHeaderView.xib 然后在ContactDetailViewController的viewDidLoad中,我将这个nib作为headerView加载。见下面的实施文件:iphone-UIViewController标题视图错误,iphone,uiviewcontroller,header,Iphone,Uiviewcontroller,Header,因此,请给出一点背景: 我有一个应用程序具有UITableViewController-ContactDetailViewController 在顶部的这个视图中,我需要一些标签和按钮,后面是一个组样式的表视图。 所以我创建了一个包含这些元素的nib文件。ContactHeaderView.xib 然后在ContactDetailViewController的viewDidLoad中,我将这个nib作为headerView加载。见下面的实施文件: #import "ContactDetailVi
#import "ContactDetailViewController.h"
#import "DisplayInfoViewController.h"
#import "ActionViewController.h"
@implementation ContactDetailViewController
@synthesize name;
@synthesize date;
@synthesize nextAction;
@synthesize nameLabel;
@synthesize usernameLabel;
@synthesize nextActionTextField;
@synthesize dateLabel;
@synthesize contactInfoButton;
@synthesize backgroundInfoButton;
@synthesize actionDoneButton;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 3;
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 0){
UIViewController *chv = [[[UIViewController alloc] initWithNibName:@"ContactHeaderView" bundle:nil] autorelease];
// self.nameLabel.text = self.name;
return chv.view;
}else{
return nil;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 300.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];
}
// Set up the cell...
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController];
// [anotherViewController release];
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
- (void)dealloc {
[name release];
[date release];
[nextAction release];
[nameLabel release];
[usernameLabel release];
[nextActionTextField release];
[dateLabel release];
[contactInfoButton release];
[backgroundInfoButton release];
[actionDoneButton release];
[super dealloc];
}
-(IBAction)displayContactInfo:(id)sender{
DisplayInfoViewController *divc = [[DisplayInfoViewController alloc] init];
divc.textView = self.nextAction;
divc.title = @"Contact Info";
[self.navigationController pushViewController:divc animated:YES];
[divc release];
}
-(IBAction)displayBackgroundInfo:(id)sender{
DisplayInfoViewController *divc = [[DisplayInfoViewController alloc] init];
divc.textView = self.nextAction;
divc.title = @"Background Info";
[self.navigationController pushViewController:divc animated:YES];
[divc release];
}
-(IBAction)actionDone:(id)sender{
ActionViewController *avc = [[ActionViewController alloc] init];
avc.title = @"Action";
avc.nextAction = self.nextAction;
[self.navigationController pushViewController:avc animated:YES];
[avc release];
}
@end
下面是头文件:
#import <UIKit/UIKit.h>
@interface ContactDetailViewController : UITableViewController {
NSString *name;
NSString *date;
NSString *nextAction;
IBOutlet UILabel *nameLabel;
IBOutlet UILabel *usernameLabel;
IBOutlet UITextField *nextActionTextField;
IBOutlet UILabel *dateLabel;
IBOutlet UIButton *contactInfoButton;
IBOutlet UIButton *backgroundInfoButton;
IBOutlet UIButton *actionDoneButton;
}
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *date;
@property (nonatomic, retain) NSString *nextAction;
@property (nonatomic, retain) IBOutlet UILabel *nameLabel;
@property (nonatomic, retain) IBOutlet UILabel *usernameLabel;
@property (nonatomic, retain) IBOutlet UITextField *nextActionTextField;
@property (nonatomic, retain) IBOutlet UILabel *dateLabel;
@property (nonatomic, retain) IBOutlet UIButton *contactInfoButton;
@property (nonatomic, retain) IBOutlet UIButton *backgroundInfoButton;
@property (nonatomic, retain) IBOutlet UIButton *actionDoneButton;
-(IBAction)displayContactInfo: (id)sender;
-(IBAction)displayBackgroundInfo: (id)sender;
-(IBAction)actionDone: (id)sender;
@end
但是,当我运行它时,会收到以下错误消息:
***由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合密钥名称标签的键值编码。”
在IB中,我已将标签/按钮/文本框连接到文件的所有者,并将文件的所有者类设置为:ContactDetailViewController
有人知道我做错了什么吗
编辑:添加了IB和连接的屏幕截图:
去:
问候,,
菲奥娜您是否在平台之间切换? 就像在旧平台上构建并在新平台上使用的nib一样? 尝试清洁所有目标可能会有所帮助。好的,我找到了解决方案。 在ContactDetailViewController中,我创建并编辑了一个视图。 然后在ViewForHeaderin部分中,我执行了以下操作:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 0){
//UIViewController *chv = [[[UIViewController alloc] initWithNibName:@"ContactHeaderView" bundle:nil] autorelease];
//headerView = chv.view;
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ContactHeaderView" owner:self options:nil];
headerView = [nib objectAtIndex:0];
self.nameLabel.text = self.name;
self.nextActionTextField.text = self.nextAction;
self.dateLabel.text = self.date;
return headerView;
}else{
return nil;
}
}
最后,在IB中,我将ContactDetailViewController中创建的IBUIView连接到视图
谢谢你的帮助,杰米。
菲奥娜嗨,杰米,谢谢你花时间看它。。。不,我不会在平台之间切换。。。我也试过打扫。。我已经删除了笔尖,重新做了一遍。我担心我的方法可能是错误的。。你觉得好看吗?还添加了一个链接,指向原始消息中的IB和连接的屏幕截图…好的,可能是因为您正在子类化UITableViewController。尝试使用UIViewController代替@interface ContactDetailViewController:UIViewController{好的..我尝试了,但得到了相同的错误…相同的位置..我尝试从ViewForHeaderInstruction方法返回视图的位置。还有其他想法吗?!ContactHeaderView.xib具有文件所有者类型ContactDetailView,并且正在使用UIViewController类类型分配。我认为您应该改进它,如果需要,请尝试创建一个单独的ContactHeaderView类您还没有一个,然后将其指定为ContactHeaderView.xib的文件所有者。如果即使这样也不起作用,那么很抱歉,我现在无法帮助您,因为我没有安装XCode。3-4小时后我回到bak家时,可能可以帮您。