UITableViewController and viewForHeaderInSection problems

Posted by Fiona on Stack Overflow See other posts from Stack Overflow or by Fiona
Published on 2010-05-20T10:06:51Z Indexed on 2010/05/20 10:10 UTC
Read the original article Hit count: 998

Hello,

So I need your help please! I've created a UITableViewController: ContactDetailViewController. In IB in the nib file, I've added a view ahead of the table view and hooked it up to headerView - a UIView declared in the .h file. I've also created a view: CustomerHeaderView However when I run the code below, Its throwing an exception at the following line: headerView = [[UIView alloc] initWithNibName:@"ContactHeaderDetail" bundle:nil];

The error being thrown is:

2010-05-20 10:59:50.405 OnePageCRM[19620:20b] * -[UIView initWithNibName:bundle:]: unrecognized selector sent to instance 0x3ca4fa0 2010-05-20 10:59:50.406 OnePageCRM[19620:20b] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '** -[UIView initWithNibName:bundle:]: unrecognized selector sent to instance 0x3ca4fa0'

So any ideas anyone?

Many thanks, Fiona

//
//  ContactDetailViewController.m
//  OnePageCRM
//
//  Created by Fiona Tighe on 19/05/2010.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ContactDetailViewController.h"
#import "DisplayInfoViewController.h"
#import "ActionViewController.h"

#define SectionHeaderHeigth 200

@implementation ContactDetailViewController
@synthesize name;
@synthesize date;
@synthesize headerView;
@synthesize nextAction;
@synthesize nameLabel;
@synthesize usernameLabel;
@synthesize nextActionTextField;
@synthesize dateLabel;
@synthesize notesTableView;
@synthesize contactInfoButton;
@synthesize backgroundInfoButton;
@synthesize actionDoneButton;


- (void)viewDidLoad {
    [super viewDidLoad];
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}


- (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 2;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 int numOfRows;
 NSLog(@"section: %d", section);
 switch (section){
  case 0:
   numOfRows = 0;
   break;
  case 1:
   numOfRows = 3;
   break;
  default:
   break; 
 }
 return numOfRows;
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
 if (section == 0){
  headerView = [[UIView alloc] initWithNibName:@"ContactHeaderDetail" bundle:nil];
//  headerView = [[UIView alloc] initWithNibName:@"ContactHeaderDetail" bundle:nil];
  return headerView;
 }else{
  return nil;
 }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
 return SectionHeaderHeigth;
}

// 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;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

-(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];
}



- (void)dealloc {
 [name release];
 [date release];
 [nextAction release];
 [nameLabel release];
 [usernameLabel release];
 [nextActionTextField release];
 [dateLabel release];
 [notesTableView release];
 [contactInfoButton release];
 [backgroundInfoButton release];
 [actionDoneButton release];
 [headerView release];
    [super dealloc];
}


@end

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uitableviewcontroller