开发者

UINavigationController Drill Down with Table View

I have a UITableView which lists the contents of my document directory. I have some zip files in that. If I touch a file in the UITableView, the corresponding zip file is unzipped and extracted in a temporary directory (NSTemporaryDirectory()).

The problem is how to navigate the contents which I extracted in a tableView. If suppose, the extracted zip file contains folders, I should able to view them in a tableView. Actually the flow should be like a drill-down.

I am able to extract the zip files, but problem is, have to navigate to them in a UITableView.

This is my didSelectRowAtIndexPath: part:

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];
}

But this is not working. It's pushing the same contents in the document directory in t开发者_如何学编程he tableView.


You need to use a UINavigationController that will handle the drill down. Each drill down is a new UITableViewController.

You need a second UITableViewController subclass that will handle displaying the files contained in the zip. It could have a NSString property that is the full path to the zip folder. It uses the list of files in that directory as the data source.

Add the original tableView (controller) to the UINavigationController's rootView at startup. When you tap the tableView that lists the zip files, you push onto the UINavigationController your second UITableViewController with a reference to the extracted files (a new folder?).

[UINavigationwController pushViewController:nextTableView animated:YES];

See this legacy code example from Apple about drilling down in a UINavigationController. Also, check out the docs on UINavigationController from Apple.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜