我的应用程序导航基于。UItextView 用于注释 UIViewController。我正在将文本数据写入文件。现在我需要以附加模式编写,我正在尝试以下代码,但每次都使用相同的文本数据写入两次,如果下一个文本数据不附加到文件中,则不附加。
- (void)saveText:(id)sender
{
[self.textview resignFirstResponder];
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
NSString *documentTXTPath = [documentsDirectory stringByAppendingPathComponent:@"Notes.txt"];
NSString *savedString = textview.text;
[savedString writeToFile:documentTXTPath atomically:YES];
NSFileHandle *myHandle = [NSFileHandle fileHandleForUpdatingAtPath:documentTXTPath ];
[myHandle seekToEndOfFile];
[myHandle writeData: [savedString dataUsingEncoding:NSUTF8StringEncoding]];
[myHandle closeFile];
}