iphone - UIViewController header view errors
Posted
by Fiona
on Stack Overflow
See other posts from Stack Overflow
or by Fiona
Published on 2010-05-21T10:01:06Z
Indexed on
2010/05/21
11:10 UTC
Read the original article
Hit count: 336
Hi there,
So to give a little background:
I've an app that has a UITableViewController- (ContactDetailViewController) In this view at the top, I require a few labels and buttons, followed by a group style tableview. So I've created a nib file containing these elements. (ContactHeaderView.xib) Then in the viewDidLoad of ContactDetailViewController I've loaded this nib as the headerView. See implementation file below:
#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
Here's the Header File:
#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
However when I run it, I get the following error message:
* Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key nameLabel.'
In IB I've hooked up the labels/buttons/textbox to the File's Owner (set the File's Owner Class to: ContactDetailViewController)
Anyone any idea what I'm doing wrong?
Regards, Fiona
© Stack Overflow or respective owner