2010-05-20 2 views
1

그래서 제발 도와주세요! UITableViewController : ContactDetailViewController을 생성했습니다. nib 파일의 IB에서 필자는 테이블 뷰 앞에 뷰를 추가하고 .h 파일에 선언 된 headerView - 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"번들 : nil]; 또한 headerView의 선언을 다음과 같이 업데이트했습니다 : UIViewController * headerView. 지금 다음 excpetion 점점 던져지는 : 인해 캐치되지 않는 예외 'NSInvalidArgumentException'응용 프로그램 종료, 이유는 : '*** - [UIViewController에 setFrame :]이 원인이 될 수있는 사항에 어떤 아이디어? 감사합니다. 피오나 – Fiona

+0

예. 그 꽤 명백한. 프레임은 뷰 컨트롤러가 아닌 뷰의 일부이므로 [thing setFrame] (또는 점 표기법은 동일) 대신 [thing.view setFrame :]을 사용해야합니다. 꽤 나에게 분명히 당신은 문서로 돌아가서 뷰와 뷰 컨트롤러가 무엇인지 이해할 필요가있다. iTunesU에서 CS193P 강의 시리즈를 적극 권장합니다. 그것의 스탠포드 유니 코스. 1 일을 기본으로 계산하면 장기적으로 시간을 절약 할 수 있습니다! – Andiih

관련 문제