UINavigationController向下钻取表视图

时间:2010-12-20 14:32:03

标签: ios cocoa-touch uitableview uinavigationcontroller drilldown

我有一个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中文档目录中的相同内容。

1 个答案:

答案 0 :(得分:1)

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

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

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

[UINavigationwController pushViewController:nextTableView animated:YES];

有关在UINavigationController中向下钻取的信息,请参阅此legacy code example from Apple。另外,请查看Apple的the docs on UINavigationController