2011-10-08 29 views
0

我有一个使用文件共享的iOS应用程序,我想将文件的文件保存在'BOOK.plist'中,只保存文件类型是.txt的files.how我保存这些文件并显示在tableview中?将文档文件保存为plist文件

希望对您有所帮助

回答

1

您不需要将您的txt文件存储在plist中。您可以将文档保存在应用程序沙箱的文档目录中。您可以通过以下代码获取路径doc目录:

NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
documentFolderPath = [searchPaths objectAtIndex: 0]; 

http://forums.macrumors.com/showthread.php?t=1233731

使用时要显示TableView中的目录会有所帮助的代码示例。希望我能帮上忙。

+0

谢谢您的帮助! –

+0

欢迎您,如果有帮助,您应该检查我答案左侧的复选标记。谢谢! – Faser

0
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectoryPath = [paths objectAtIndex:0]; 
NSFileManager *manager = [NSFileManager defaultManager]; 
self.frlistName2 = [[manager contentsOfDirectoryAtPath:documentsDirectoryPath error:nil]pathsMatchingExtensions:[NSArray arrayWithObject:@"txt"]]; 

NSString *obj = @".txt"; 
frlisturls2 = [[NSMutableArray alloc] initWithObjects:nil]; 
NSString *temp; 
NSMutableString *mp3Path = [[NSMutableArray alloc] init]; 
int j =0; 
for(int i =0 ; i< [frlistName2 count]; i++) 
{ 
    mp3Path = [NSMutableString stringWithString:documentsDirectoryPath]; 
    [mp3Path appendString:@"/"]; 

    temp = [frlistName2 objectAtIndex:i]; 
    if([temp hasSuffix :obj]) 
    { 
     [mp3Path appendString: temp]; 
     [frlisturls2 addObject: mp3Path]; 
     j++; 
    } 
      [mp3Path release]; 

    NSLog(@"frlisturls2 is%@:",frlisturls2); 
} 

上面的代码显示从文件共享iTunes的一个数组中的文件,并保存这些文件的URL