Save Text From UITextVIEW?

限于喜欢 提交于 2019-12-12 04:07:46

问题


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

I desperately need help.

Thx


回答1:


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

My guess, however, is this line:

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

I think you probably mean:

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

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



来源:https://stackoverflow.com/questions/3995482/save-text-from-uitextview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!