您好如何保存和检索UITextView中的文本?如果有人知道请帮助我。使用plist给我一些示例代码。 谢谢。
答案 0 :(得分:1)
查看stringWithContentsOfFile:encoding:error:
和writeToFile:atomically:encoding:error:
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myfile.plist"];
NSError *error = nil;
// read from plist:
NSString *text = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
if (!text) {
NSLog(@"Error reading - %@", error);
}
textView.text = text;
// save to plist:
NSString *text = textView.text
if (![text writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error]) {
NSLog(@"Error saving - %@", error);
}