gpt4 book ai didi

ios - UINavigationController 使用表格 View 向下钻取

转载 作者:行者123 更新时间:2023-11-29 13:50:50 26 4
gpt4 key购买 nike

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

最佳答案

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

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

启动时将原来的tableView(controller)添加到UINavigationController的rootView中。当您点击列出 zip 文件的 tableView 时,您将第二个 UITableViewController 推到 UINavigationController 上,并引用提取的文件(新文件夹?)。

[UINavigationwController pushViewController:nextTableView animated:YES];

查看此 legacy code example from Apple关于在 UINavigationController 中向下钻取。另外,查看 the docs on UINavigationController来自 Apple。

关于ios - UINavigationController 使用表格 View 向下钻取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4490557/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com