文件句柄选项不会出现

时间:2012-11-23 23:18:38

标签: iphone ios nsfilemanager filehandle

我在教程中键入了以下代码,但我无法让它工作...... 它说“没有可见的@interface为'NSFilemanager'声明选择器..... 对于[fileHandle seekToEndOfFile]; [fileHandle writeData:[resultLine dataUsingEncoding:NSUTF8StringEncoding]]; [fileHandle closeFile];部分..

任何想法是什么问题,因为我经历了很多次.. 谢谢 垫

 - (IBAction)SaveText:(id)sender {

NSString *resultLine =[NSString stringWithFormat:@"%@\n",
                       self.inputText];

NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask,YES)objectAtIndex:0];
// textMsg.text = docPath;

NSString *savedTextMsg =[docPath stringByAppendingPathComponent:@"textMessage.csv"];

if (![[NSFileManager defaultManager] fileExistsAtPath:docPath]) {
    [[NSFileManager defaultManager]
     createFileAtPath:savedTextMsg contents:nil attributes:nil];
}
NSFileManager *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:savedTextMsg];
[fileHandle seekToEndOfFile];
[fileHandle writeData:[resultLine dataUsingEncoding:NSUTF8StringEncoding ]];
[fileHandle closeFile];

self.textMsg.text =@"";
NSLog(@"info saved");

}

1 个答案:

答案 0 :(得分:1)

如果你改变了会有所帮助:

NSFileManager *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:savedTextMsg];

为:

NSFileHandle *fileHandle = [NSFileHandle fileHandleForUpdatingAtPath:savedTextMsg];

注意变量的类型。