本文介绍了从UITextVIEW保存文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题:我可以找到一种方法在NSString中正确保存我的UITextView。
我创建了4个UITextViews,我希望它们保存在同一个文件中。
下面代码:

I'm having a problem : i can' find a way to save properly my UITextView in a NSString.I have created 4 UITextViews and i want them to be saved in the same file.Heres the code :

-(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

推荐答案

你真的没有给我们太多的帮助。没有错误消息。没有关于你尝试过什么或失败的建议。

You don't really give us much to go on. No error messages. No suggestion of what you've tried or where it failed.

我的猜测是这一行:

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

我想你可能意味着:

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

否则你的文件名看起来像 /some/pathSaveData.plist ,显然无效。

Otherwise your filename will look something like /some/pathSaveData.plist, which, obviously, is not valid.

这篇关于从UITextVIEW保存文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 09:34