2010-10-22 4 views
0

J'ai un problème: je peux trouver un moyen d'enregistrer correctement mon UITextView dans un NSString. J'ai créé 4 UITextViews et je veux qu'ils soient sauvegardés dans le même fichier. Heres le code:Sauvegarder le texte de UITextVIEW?

-(void)destinataireTextView { 

self.destiView = [[[UITextView alloc] initWithFrame:CGRectMake(200, 160, 150, 120)] autorelease]; 
     [self.view addSubview: self.destiView]; 
} 

-(void)expediteurTextView { 

self.expediView = [[[UITextView alloc] initWithFrame:CGRectMake(430, 200, 150, 120)] autorelease]; 
     [self.view addSubview: self.expediView]; 
} 

-(void)objetTextView { 

self.objetView = [[[UITextView alloc] initWithFrame:CGRectMake(200, 295, 150, 120)] autorelease]; 
     [self.view addSubview: self.objetView]; 
} 

-(void)corpsTextView { 

self.corpsView = [[[UITextView alloc] initWithFrame:CGRectMake(200, 335, 150, 120)] autorelease]; 
     [self.view addSubview: self.corpsView]; 
} 

-(void)viewDidLoad{ 

[super viewDidLoad]; 
     [self destinataireTextView]; 
[self expediteurTextView]; 
[self objetTextView]; 
[self corpsTextView]; 
} 

I've tried this piece of code : 

-(void)viewDidLoad 

[super viewDidLoad]; 

NSString *filePath = [self pathOfFile]; 

if ([[NSFileManager defaultManager]fileExistsAtPath:filePath]) { 

    NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath]; 
    desti.text = [array objectAtIndex:0]; 
    [array release]; 
} 

UIApplication *notif = [UIApplication sharedApplication]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTermite:) name:UIApplicationWillTerminateNotification object:notif]; 
} 

-(NSString *) pathOfFile{ 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentFolder = [paths objectAtIndex:0]; 
return [documentFolder stringByAppendingFormat:@"SaveData.plist"]; 
} 

-(void)applicationWillTermite:(NSNotification *)notification{ 

NSMutableArray *save = [[NSMutableArray alloc] init]; 
[save addObject:field1.text]; 
[save writeToFile:[self pathOfFile]atomically:YES]; 
[save release]; 
} 

Je désespérément besoin d'aide.

Thx

+1

Je ne connais pas votre application, mais la mienne jamais 'Termite. Faute de frappe? ou la cause de votre problème? –

Répondre

2

Vous ne nous donnez pas vraiment beaucoup à faire. Aucun message d'erreur Aucune suggestion de ce que vous avez essayé ou où il a échoué.

Je pense, cependant, est cette ligne:

return [documentFolder stringByAppendingFormat:@"SaveData.plist"]; 

Je pense que vous voulez dire probablement:

return [documentFolder stringByAppendingPathComponent:@"SaveData.plist"]; 

Sinon, votre nom ressemblera à quelque chose comme /some/pathSaveData.plist, qui, évidemment, n'est pas valide.

+0

Thx, je vais essayer ça – Gaspard