2010-10-22 89 views
0

我有一個問題:我可以'找到一種方法來正確保存我的UITextView在NSString中。 我已經創建了4個UITextViews,我希望它們被保存在同一個文件中。 繼承人的代碼:從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]; 
} 

我迫切需要幫助。

THX

+1

我不知道你的應用程序,但我從來沒有'白蟻的。錯字?或者你的問題的原因? – 2010-10-22 09:29:40

回答

2

你不會真的給我們很大的繼續下去。沒有錯誤消息。沒有建議你嘗試過什麼或失敗的地方。

我的猜測,但是,這條線:

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

我想你大概的意思是:

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

否則你的文件名看起來就像/some/pathSaveData.plist,顯然這是無效的。

+0

Thx,我要試試這個 – Gaspard 2010-10-22 09:43:55