【发布时间】:2012-12-01 10:17:03
【问题描述】:
在我的应用程序中,我将记录文件保存在文档目录中。然后稍后从文档目录中获取所有这些文件,并在我的 mainClass 中显示所有这些文件,其中我有 UITableview。 当我单击此 mainClass Tableview 的任何行时,它会转到下一个类,我在其中播放此文件,删除此文件并将此文件发送到我最喜欢的录音类,在那里我有 Tableview。现在我的播放按钮操作方法和删除按钮操作方法工作正常,但我不知道如何将此文件发送到我的 Favurite Class Tableview。现在我在这里显示我的删除按钮代码,通过它我们可以获得基本的想法。
-(IBAction)deleteFile
{
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
NSString *documentPath = [docsDir stringByAppendingPathComponent:@"MyRecordings"];
NSString *soundFilePath = [documentPath stringByAppendingPathComponent:fileToPlay];
recordedTmpFile = [NSURL fileURLWithPath:soundFilePath];
[[NSFileManager defaultManager] removeItemAtURL:recordedTmpFile error:nil];
}
作为我的删除按钮代码显示我们如何删除我从 MainTableview 中选择的当前录制文件。现在如果用户想要将当前录制文件发送到我最喜欢的类 Tableview 而不是删除它那么我是否使用另一个文档文件夹如果答案是肯定的?那么我们如何将当前文件(recordedTmpFile)保存在这个新的 Document 文件夹中。
-(IBAction)AddToFavourite
{
NSArray *dirPaths1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir1 = [dirPaths1 objectAtIndex:0];
NSString *documentPath1 = [docsDir1 stringByAppendingPathComponent:@"MyFovouriteRecordings"];
// How to pass here the Current Recording File (recordedTmpFile) to this new document Folder.
}
当我 NSlog 记录的TmpFile 显示结果:file://localhost/Users/Umar/Library/Application%20Support/iPhone%20Simulator/4.2/Applications/9219677A-B0E3-4B78-B2E5-FEA49D689618/Documents/MyRecordings/06 :Dec:12_05:54:07%20PM+Active%20song
任何帮助都会得到帮助。谢谢
【问题讨论】:
-
可能是更好的方法,而不是将此文件移动到收藏夹文件夹中,您应该为收藏夹创建一个数据库,并在 AddToFavourite 操作时将文件路径保存在数据库中,并且每当您想显示收藏夹录音时从数据库中获取数据并在 tableview 中显示。
-
感谢@prasad 的快速响应,如果我们将当前文件保存到另一个文档文件夹,然后在 FavouritClass tableview 中从该文档中获取数据。因为我已经为我的 MainTableview 使用了 Document 文件夹。你能不能给我任何想法。
-
你可以使用stackoverflow.com/questions/1762836/…创建收藏夹和复制文件使用NSFileManager *fileManager = [NSFileManager defaultManager]; [fileManager copyItemAtPath:docPath toPath:favFloderPath error:&error];
-
请根据我的要求发布您的答案。我认为这种方法对我有用。
标签: iphone xcode uitableview document