开发者

How to save and retrieve text which is in UITextView using plist

Hi How to sav开发者_如何学Goe and retrieve text which is in UITextView? If anybody knows please help me. Give me some sample code using plist. Thank you.


Have a look at stringWithContentsOfFile:encoding:error: and 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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜