iphone - 在 UITableView 的 iOS 文档目录中列出保存的文件?

我已经设置了以下代码来将文件保存到文档目录:

NSLog(@"Saving File...");

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.reddexuk.com/logo.png"]];
AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"logo.png"];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

[operation start];

但是,我希望在成功保存后将每个文件添加到 UITableView。当点击 UITableView 中的文件时,我希望 UIWebView 导航到该文件(全部脱机)。

另外 - 我怎样才能获得文件名和结尾,例如“logo.png”而不是 http://www.reddexuk.com/logo.png ?

我该怎么做?

最佳答案

这是我用来获取目录内容的方法。

-(NSArray *)listFileAtPath:(NSString *)path
{
    //-----> LIST ALL FILES <-----//
    NSLog(@"LISTING ALL FILES FOUND");

    int count;

    NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];
    for (count = 0; count < (int)[directoryContent count]; count++)
    {
        NSLog(@"File %d: %@", (count + 1), [directoryContent objectAtIndex:count]);
    }
    return directoryContent;
}

https://stackoverflow.com/questions/8376511/

相关文章:

iphone - 绘制平滑曲线 - 所需方法

ios - UILabel 根据要显示的文本自动调整大小

iphone - 如何检查数组是空还是空?

iphone - 如何在当前 UITableViewController 上方添加一个 UIView

iphone - NSCharacterSet:如何将 "_"添加到 alphanumericCha

objective-c - 所有异常断点在模拟器上无缘无故停止

ios - 如何以编程方式使用 UIView autoresizingMask 属性?

objective-c - 如何在 Objective-C 中使用 Swift 字符串枚举?

objective-c - 如何本地化 iOS Storyboard

iphone - 在 bundle 中找不到名为 'Main' 的 Storyboard