【发布时间】:2010-12-27 06:12:10
【问题描述】:
我有一个 tableView 列出了我的文档目录的内容。我有一些 zip 文件。如果我在 tableView 中触摸一个文件,相应的 zip 文件将被解压缩并提取到一个临时目录中(在我的情况下为newFilePath)。解压后的内容列在下一个 tableView 中。当我点击后退按钮时,目录中的内容又被列出来了。
例如,假设我的文档目录中有四个 zip 文件。
songs.zip、videos.zip、files.zip、calculation.zip
当我运行应用程序时,所有四个文件都列在 tableView 中。当我触摸songs.zip 时,这个文件被提取到newFilePath 中,并且它的内容被推送到下一个tableView。当我触摸回来的时候,之前的tableView,即文档目录中的四个文件又被列出来了。一切都很完美。
问题是,newFilePath 中提取的文件本身仍然存在。它们不必要地占用内存。我希望在我触摸后退按钮时将它们从该路径中删除,即我想在触摸后退按钮时将 newFilePath 设为空。
我试过了。但是,没有用。我在viewWillAppear: 和viewWillDisappear: 中尝试了removeItemAtPath: 方法。但它在这两种情况下都不起作用。
还有其他方法可以跟踪后退按钮的操作吗?我希望在触摸后退按钮时发生一个事件。因此,请通过分享您的想法来帮助我。这是我的验证码。
这是我的didSelectRowAtIndexPath:
NSString *filePath = //filePath
if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSLog(@"File exists at path: %@", filePath);
} else {
NSLog(@"File does not exists at path: %@", filePath);
}
ZipArchive *zip = [[ZipArchive alloc] init];
NSString *newFilePath = //newFilePath
[[NSFileManager defaultManager] createDirectoryAtPath:newFilePath withIntermediateDirectories:NO attributes:nil error:nil];
BOOL result = NO;
if([zip UnzipOpenFile:filePath]) {
//zip file is there
if ([zip UnzipFileTo:newFilePath overWrite:YES]) {
//unzipped successfully
NSLog(@"Archive unzip Success");
result= YES;
} else {
NSLog(@"Failure To Extract Archive, maybe password?");
}
} else {
NSLog(@"Failure To Open Archive");
}
iDataTravellerAppDelegate *AppDelegate = (iDataTravellerAppDelegate *)[[UIApplication sharedApplication] delegate];
//Prepare to tableview.
MyFilesList *myFilesList = [[MyFilesList alloc] initWithNibName:@"MyFilesList" bundle:[NSBundle mainBundle]];
//Increment the Current View
myFilesList.CurrentLevel += 1;
viewPushed = YES;
//Push the new table view on the stack
myFilesList.directoryContent = [AppDelegate getTemporaryDirectoryItemList:newFilePath];
[myFilesList setTitle:detailedViewController.strName];
[self.navigationController pushViewController:myFilesList animated:YES];
[myFilesList release];
感谢您的回答。
【问题讨论】:
标签: iphone objective-c uitableview ios4 uinavigationcontroller