UITableViewController和viewForHeaderInSection问题

时间:2010-05-20 10:06:51

标签: iphone uitableview

所以我需要你的帮助! 我创建了UITableViewControllerContactDetailViewController。 在nib文件中的IB中,我在表视图之前添加了一个视图,并将其连接到headerView - .h文件中声明的UIView。 我还创建了一个视图:CustomerHeaderView 但是,当我运行下面的代码时,它会在以下行中抛出异常:

headerView = [[UIView alloc] initWithNibName:@"ContactHeaderDetail" bundle:nil];

抛出的错误是:

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

所以任何人的想法?

非常感谢, 菲奥娜

//
//  ContactDetailViewController.m
//  X
//
//  Created by Fiona 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

1 个答案:

答案 0 :(得分:2)

headerView = [[UIView alloc] initWithNibName:@"ContactHeaderDetail" bundle:nil];

UIView没有XIB或initWithNibName函数。

您的意思是制作UIViewController吗?