【问题标题】:iPhone DrillDowniPhone 向下钻取
【发布时间】:2011-05-29 22:33:46
【问题描述】:

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

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

我可以提取 zip 文件,但问题是,必须在 tableView 中导航它们。请给我一些想法或一些源代码来帮助我解决问题。

这是我的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的文档目录中推送相同的内容

请帮帮我..

谢谢你..

【问题讨论】:

    标签: iphone uitableview iphone-sdk-3.0


    【解决方案1】:

    您在哪里告诉您的RootViewController 开辟一条新路径?对我来说,您似乎再次使用旧路径打开相同的RootViewController,所以它肯定会再次打开相同的路径

    【讨论】:

    • 是的。我在 RootViewController 本身内部调用 RootViewController。那我该怎么办?
    • 不,我不是这个意思,可以称呼自己,但你在哪里告诉新路径?你有一个变量,例如 rvController.myPath = @"my/new/path";然后在 RVC 初始化方法中读取 myPath 变量并在该路径中显示所有内容
    【解决方案2】:

    你应该添加一个属性来设置你的控制器类的当前文件路径。 您可以编写一个指定的初始化器,如:

    - (id)initWithDirectoryPath:(NSString*)path {
        self = [super initWithNibName:@"DirectoryViewController" bundle:nil];
        if (self != nil) {
            self.directoryPath = path;
            self.navigationItem.title = [path lastPathComponent];
        }
    }
    

    然后您可以创建视图控制器并将其推送到导航控制器上:

    DirectoryViewController *viewController = [[DirectoryViewController alloc] initWithDirectoryPath:path];
    [self.navigationController pushViewController:viewController animated:YES];    
    [viewController release];
    

    别忘了释放 VC!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多