2010-05-20 65 views
1

所以我需要你的帮助! 我创建了一个UITableViewControllerContactDetailViewController。 在笔尖文件中的IB中,我在表格视图前添加了一个视图,并将它连接到headerView - 在.h文件中声明的UIView。 我还创建了一个观点:CustomerHeaderView 然而,当我运行下面的代码,它在下面的行抛出一个异常:UITableViewController和viewForHeaderInSection问题

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 

回答

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

UIView的没有XIB,或initWithNibName功能。

你的意思是做一个UIViewController

+0

嗨Andiih,感谢您花时间看它..我实际上有一个UIViewController在一个点上,但改变了它。 所以我回到了UIViewController。 headerView = [[UIViewController alloc] initWithNibName:@“ContactHeaderDetail”bundle:nil]; 我也更新了headerView的声明:UIViewController * headerView。 现在收到以下错误时抛出抛出: 终止应用程序由于未捕获的异常“NSInvalidArgumentException”,原因:“*** - [UIViewController中SETFRAME:]: 上什么可能导致此任何想法? 谢谢 菲奥娜 – Fiona 2010-05-20 10:17:11

+0

是的。它非常明显。该框架是视图的一部分(而不是视图控制器),因此您需要使用[thing.view setFrame:]而不是[thing setFrame](或点符号等值)。对我来说很明显,你需要回到文档并理解视图和视图控制器是什么。我强烈建议在iTunesU上使用CS193P讲座系列。它的斯坦福大学课程。花1天的时间现在确定基础知识将节省时间从长远来看! – Andiih 2010-05-20 12:07:07

相关问题