我有一个 tableView 列出了我的文档目录的内容。我有一些 zip 文件。如果我在 tableView 中触摸一个文件,相应的 zip 文件将被解压缩并提取到一个临时目录中(newFilePath
在我的情况下)。解压后的内容列在下一个 tableView 中。当我触摸后退按钮时,目录中的内容再次列出。
例如,假设我的文档目录中有四个 zip 文件。
歌曲.zip、视频.zip、文件.zip、计算.zip
当我运行应用程序时,所有四个文件都列在 tableView 中。当我触摸songs.zip 时,该文件被提取到其中,newFilePath
并将其内容推送到下一个tableView。当我触摸回来时,之前的tableView,即文档目录中的四个文件又被列出来了。一切都很完美。
问题是,提取的文件newFilePath
本身仍然存在。它们不必要地占用内存。当我触摸后退按钮时,我希望它们从该路径中删除,即,我想在触摸后退按钮newFilePath
时清空。
我试过了。但是,没有用。我尝试removeItemAtPath:
了 inviewWillAppear:
和 in 中的方法viewWillDisappear:
。但它在这两种情况下都不起作用。
还有其他方法可以跟踪后退按钮的操作吗?我希望在触摸后退按钮时发生一个事件。因此,请通过分享您的想法来帮助我。这是我的验证码。
这是我的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];
谢谢您的回答。