2010-05-20 3 views
1

Так что мне нужна ваша помощь! Я создал UITableViewController: ContactDetailViewController. В IB в файле nib я добавил представление перед представлением таблицы и подключил его до headerView - UIView, объявленного в файле .h. Я также создал вид: 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 «s не имеют XIB или initWithNibName функции.

Вы хотите сделать UIViewController?

+0

Hi Andiih, спасибо, что нашли время, чтобы посмотреть на это. У меня на самом деле был UIViewController, но он изменил его. Итак, я вернулся в UIViewController. headerView = [[UIViewController alloc] initWithNibName: @ "ContactHeaderDetail" bundle: nil]; Я также обновил объявление headerView: UIViewController * headerView. Теперь получает следующее excpetion бросает: Нагрузочное приложение из-за неперехваченное исключение «NSInvalidArgumentException», причина: «*** - [UIViewController setFrame]: Любых идей о том, что может быть причиной этого? Thanks Fiona – Fiona

+0

Да. Это довольно очевидно. Рамка является частью представления (а не контроллера вида), поэтому вам нужно использовать [thing.view setFrame:], а не [вещь setFrame] (или равнозначная точечная нотация). Для меня довольно очевидно, что вам нужно вернуться к документации и понять, что такое просмотр и контроллер представления. Я очень рекомендую серию лекций CS193P на iTunesU. Это курс Стэнфордского университета. Проведя 1 день, теперь выяснение основ поможет сэкономить время в долгосрочной перспективе! – Andiih

Смежные вопросы