1

我有一个UITableView列出我的文档目录的内容。我有一些 zip 文件。如果我触摸 中的文件UITableView,相应的 zip 文件将被解压缩并提取到临时目录 ( NSTemporaryDirectory()) 中。

问题是如何导航我在 tableView 中提取的内容。如果假设,提取的 zip 文件包含文件夹,我应该能够在 tableView 中查看它们。实际上,流程应该像向下钻取。

我能够提取 zip 文件,但问题是,必须在UITableView.

这是我的didSelectRowAtIndexPath:部分:

NSString *filePath = //filePath;
if ([[NSFileManager defaultManager]fileExistsAtPath:filePath]) {
    NSLog(@"File exists at path: %@",filePath);         
} else {            
    NSLog(@"File does not exists at path: %@", filePath);       
}               

NSString *tmpDir =NSTemporaryDirectory();       
ZipArchive *zip = [[ZipArchive alloc] init];
BOOL result = NO;

if ([zip UnzipOpenFile:filePath]) {
    //zip file is there
    if ([zip UnzipFileTo:tmpDir overWrite:YES]) {
        //unzipped successfully
        NSLog(@"Archive unzip Success");
        result= YES;
    } else {
        NSLog(@"Failure To Extract Archive, maybe password?");
    }   
} else  {
    NSLog(@"Failure To Open Archive");
}       

if ([[NSFileManager defaultManager] fileExistsAtPath:tmpDir isDirectory:&isDir] && isDir) {
    NSLog(@"Its Folder");
    //Prepare to tableview.             
    RootViewController *rvController =[[RootViewController alloc]initWithNibName:@"RootViewController"bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:rvController animated:YES];
}

但这不起作用。它在 tableView 的文档目录中推送相同的内容。

4

1 回答 1

1

您需要使用 UINavigationController 来处理向下钻取。每个向下钻取都是一个新的 UITableViewController。

您需要第二个 UITableViewController 子类来处理显示 zip 中包含的文件。它可能有一个 NSString 属性,它是 zip 文件夹的完整路径。它使用该目录中的文件列表作为数据源。

在启动时将原始的 tableView(控制器)添加到 UINavigationController 的 rootView。当您点击列出 zip 文件的 tableView 时,您会将第二个 UITableViewController 推送到 UINavigationController 上,并引用提取的文件(新文件夹?)。

[UINavigationwController pushViewController:nextTableView animated:YES];

请参阅 Apple 的这个遗留代码示例,了解如何在UINavigationController. 另外,请查看Apple提供的有关 UINavigationController 的文档。

于 2010-12-20T14:35:52.780 回答