plantage a cause d'un [[NSApplication sharedApplication] setDelegate:self];

clampinclampin Membre
Bonjour,

J'ai suivit le petit tutoriel du site du zéro -> http://www.siteduzero.com/tutoriel-3-176940-un-carnet-de-commandes.html. Mon application fonctionnait jusqu'a ce que j'arrive à  la partie "Des petits ajouts qui font tout le charme !" ou l'on sauve le contenu de la NSTableView dans un fichier.

J'ai je pense suivit exactement ce tutoriel et mon appli ce plante

capturedcran20110110074.jpg

Voici le code de mon ControlerCommande.h
<br />[#import &lt;Cocoa/Cocoa.h&gt;<br /><br />@interface ControlerCommande : NSObject {<br />&nbsp; &nbsp; IBOutlet id boutonSupprimer;<br />&nbsp; &nbsp; IBOutlet id table;<br />	NSMutableArray * commandes;<br />}<br />- (IBAction)ajouter:(id)sender;<br />- (IBAction)supprimer:(id)sender;<br /><br />- (int) numberOfRowsInTableView:(NSTableView *)uneTable;<br />- (id) tableView:(NSTableView *)uneTable objectValueForTableColumn:(NSTableColumn *)uneColonne row:(int)i ;<br />- (void) tableView:(NSTableView *)uneTable setObjectValue:(id)objet forTableColumn:(NSTableColumn *)uneColonne row:(int)i ;<br /><br />- (void) miseAJour;<br />@end<br />




Voici le code de mon ControlerCommande.m

<br /><br />#import &quot;ControlerCommande.h&quot;<br /><br />@implementation ControlerCommande<br /><br /><br />-(id) init {<br />	<br />	[super init];<br />	NSString * chemin = [@&quot;~/commandes sauvegardées&quot; stringByExpandingTildeInPath];<br />	NSArray *contenu = [NSArray arrayWithContentsOfFile:chemin];<br />	<br />	commandes = [[NSMutableArray alloc] init];<br />	<br />	if (!contenu)<br />		commandes = [commandes init];<br />	else <br />		commandes = [commandes initWithArray:contenu];<br />	<br />		[[NSApplication sharedApplication] setDelegate:self];<br />	<br /><br />	<br />	return self;<br />}<br /><br />- (void) applicationWillTerminate:(NSNotification *)notification <br />{<br />&nbsp; &nbsp; NSString * chemin = [@&quot;~/commandes sauvegardées&quot; stringByExpandingTildeInPath];<br />&nbsp; &nbsp; [commandes writeToFile:chemin atomically:YES];<br />}<br /><br />- (IBAction)ajouter:(id)sender {<br />	<br />	NSMutableDictionary * commande = [NSMutableDictionary dictionary];<br />	[commandes addObject:commande];<br />	[self miseAJour];<br />&nbsp; &nbsp; <br />}<br /><br />- (IBAction)supprimer:(id)sender {<br />	<br />	int ligne = [table selectedRow];<br />	[commandes removeObjectAtIndex:ligne];<br />	[self miseAJour];<br />&nbsp; &nbsp; <br />}<br /><br />-(void) miseAJour<br />{<br />	[table reloadData];<br />}<br /><br />- (int) numberOfRowsInTableView:(NSTableView *)uneTable<br />{<br />	return [commandes count];<br />}<br /><br />- (id) tableView:(NSTableView *)uneTable<br />objectValueForTableColumn:(NSTableColumn *)uneColonne<br />			 row:(int)i<br />{<br />	NSString *identifier = [uneColonne identifier];<br />	return [[commandes objectAtIndex:i] objectForKey:identifier];<br />}<br /><br />- (void) tableView:(NSTableView *)uneTable setObjectValue:(id)objet forTableColumn:(NSTableColumn *)uneColonne row:(int)i ;<br />{<br />	NSString *identifier = [uneColonne identifier];<br />	NSMutableDictionary * commande = [commandes objectAtIndex:i];<br />	<br />	[commande setObject:objet forKey:identifier];<br />}<br />@end<br />

Réponses

  • laudemalaudema Membre
    22:41 modifié #2
    Peut être parce que tu fais deux fois init pour ton objet commandes ?
    <br /><br />commandes = [[NSMutableArray alloc] init]; //Ce init n&#39;est pas dans le code source de ton exemple<br />	<br />	if (!contenu)<br />		commandes = [commandes init];<br />&nbsp; &nbsp; &nbsp; &nbsp; else <br />		commandes = [commandes initWithArray:contenu];<br />
    

    Ceci étant il n'est pas habituel de faire alloc sans suivre par init c'est même déconseillé dans la documentation.
  • cyranocyrano Membre
    22:41 modifié #3
    Quel titre!  :D

    il faut lire les traces, et tout devient clair.

    une exception est levée par initWithCapacity qui est appelée par un objet concret. eh oui il a deja été crée.

    laudema a donnée la solution.
Connectez-vous ou Inscrivez-vous pour répondre.