iPhone DrillDown

时间:2010-12-23 11:43:49

标签: iphone uitableview iphone-sdk-3.0

海全都。我有一个tableView,它列出了我的文档目录的内容。我有一些zip文件。如果我触摸tableView中的文件,则会在临时目录(NSTemporaryDirectory())中解压缩相应的zip文件并将其解压缩。

问题是如何导航我在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

的文档目录中推送相同的内容

请帮帮我..

谢谢..

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

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

- (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!