1

我有一個UITableView其中列出了我的文檔目錄的內容。我有一些zip文件。如果我觸摸UITableView中的文件,則會將相應的zip文件解壓縮並解壓縮到臨時目錄(NSTemporaryDirectory())中。UINavigationController向下鑽取表視圖

問題是如何瀏覽我在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

您需要使用UINavigationController來處理向下鑽取。每次深入挖掘都是一個新的UITableViewController。

您需要第二個UITableViewController子類來處理顯示zip中包含的文件。它可能有一個NSString屬性,它是zip文件夾的完整路徑。它使用該目錄中的文件列表作爲數據源。

在啓動時將原始tableView(控制器)添加到UINavigationController的rootView。當你點擊列出zip文件的tableView時,你可以通過引用提取的文件(一個新文件夾?)將UITableViewController推入UINavigationController。

[UINavigationwController pushViewController:nextTableView animated:YES]; 

請參閱本legacy code example from Apple約在UINavigationController下鑽。另外,請查看Apple的the docs on UINavigationController