2010-05-21 5 views
1

Donc, pour donner un peu de fond:iphone - UIViewController erreurs vue d'en-tête

J'ai une application qui a un UITableViewController- (ContactDetailViewController) Dans ce point de vue en haut, je requiers quelques étiquettes et boutons, suivi par une tableview de style groupe. J'ai donc créé un fichier nib contenant ces éléments. (ContactHeaderView.xib) Ensuite, dans viewDidLoad de ContactDetailViewController, j'ai chargé cette pointe en tant que headerView. Voir le dossier de mise en œuvre ci-dessous:

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

@implementation ContactDetailViewController 

@synthesize name; 
@synthesize date; 
@synthesize nextAction; 
@synthesize nameLabel; 
@synthesize usernameLabel; 
@synthesize nextActionTextField; 
@synthesize dateLabel; 
@synthesize contactInfoButton; 
@synthesize backgroundInfoButton; 
@synthesize actionDoneButton; 


- (void)viewDidLoad { 
    [super viewDidLoad]; 
} 


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


// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
     return 3; 
} 

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
    if (section == 0){ 
     UIViewController *chv = [[[UIViewController alloc] initWithNibName:@"ContactHeaderView" bundle:nil] autorelease]; 
    // self.nameLabel.text = self.name; 
     return chv.view; 
    }else{ 
     return nil; 
    } 
} 

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


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



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

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

@end 

Voici le fichier d'en-tête:

#import <UIKit/UIKit.h> 


@interface ContactDetailViewController : UITableViewController { 

    NSString *name; 
    NSString *date; 
    NSString *nextAction; 

    IBOutlet UILabel *nameLabel; 
    IBOutlet UILabel *usernameLabel; 
    IBOutlet UITextField *nextActionTextField; 
    IBOutlet UILabel *dateLabel; 

    IBOutlet UIButton *contactInfoButton; 
    IBOutlet UIButton *backgroundInfoButton; 
    IBOutlet UIButton *actionDoneButton; 

} 
@property (nonatomic, retain) NSString *name; 
@property (nonatomic, retain) NSString *date; 
@property (nonatomic, retain) NSString *nextAction; 

@property (nonatomic, retain) IBOutlet UILabel *nameLabel; 
@property (nonatomic, retain) IBOutlet UILabel *usernameLabel; 
@property (nonatomic, retain) IBOutlet UITextField *nextActionTextField; 
@property (nonatomic, retain) IBOutlet UILabel *dateLabel; 

@property (nonatomic, retain) IBOutlet UIButton *contactInfoButton; 
@property (nonatomic, retain) IBOutlet UIButton *backgroundInfoButton; 
@property (nonatomic, retain) IBOutlet UIButton *actionDoneButton; 

-(IBAction)displayContactInfo: (id)sender; 
-(IBAction)displayBackgroundInfo: (id)sender; 
-(IBAction)actionDone: (id)sender; 


@end 

Cependant quand je le lance, je reçois le message d'erreur suivant:

*** Mettre fin application en raison d'une exception non interceptée 'NSUnknownKeyException', raison: '[setValue: forUndefinedKey:]: cette classe n'est pas compatible avec le codage de valeur de clé pour la clé nameLabel.'

Dans IB j'ai accroché les étiquettes/boutons/zone de texte au propriétaire (set de classe propriétaire du fichier à: ContactDetailViewController) du fichier

Toute idée de ce que je fais mal?

Modifier: Ajout d'une capture d'écran de IB et connexions: Aller à: http://www.freeimagehosting.net/uploads/44c65c7ef3.png

Cordialement, Fiona

Répondre

0

Vous commutent entre les plates-formes? Comme plume comme construit sur l'ancienne plate-forme et utilisé sur le nouveau? Essayez de nettoyer toutes les cibles, cela pourrait aider.

+0

Salut jAmi, Merci d'avoir pris le temps de le regarder ... Non, je ne change pas de plate-forme ... Et j'ai essayé de nettoyer .. J'ai supprimé la plume et l'ai refaite. J'étais inquiet que ma méthode puisse être fausse ... cela vous semble-t-il bon? Ajout d'un lien vers une capture d'écran de IB et des connexions dans le message d'origine ... – Fiona

+0

OK, l'erreur est peut-être due au fait que vous sous-classez UITableViewController. Essayez plutôt UIViewController comme @interface ContactDetailViewController: UIViewController { – jAmi

+0

Ok .. je l'ai essayé mais en obtenant la même erreur ... même endroit .. où j'essaie de renvoyer la vue de la méthode viewForHeaderInSection. D'autres idées ?! – Fiona

0

Ok, j'ai trouvé une solution. Dans ContactDetailViewController, je crée et IBOutlet UIView. Puis, en viewForHeaderInSection j'ai fait ce qui suit:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
    if (section == 0){ 
     //UIViewController *chv = [[[UIViewController alloc] initWithNibName:@"ContactHeaderView" bundle:nil] autorelease]; 
     //headerView = chv.view; 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ContactHeaderView" owner:self options:nil]; 
     headerView = [nib objectAtIndex:0]; 
     self.nameLabel.text = self.name; 
     self.nextActionTextField.text = self.nextAction; 
     self.dateLabel.text = self.date; 
     return headerView; 
    }else{ 
     return nil; 
    } 
} 

Enfin, dans IB I connecté le IBOutlet UIView créé en ContactDetailViewController, à la vue.

Merci pour votre aide jAmi. Fiona

Questions connexes