开发者

iPhone - tracking back button

开发者 https://www.devze.com 2023-01-31 21:27 出处:网络
I have a tableView which lists the contents of my document directory. I have some zip files in that. If I touch a file in the tableView, the corresponding zip file is unzipped and extracted in a tempo

I have a tableView which lists the contents of my document directory. I have some zip files in that. If I touch a file in the tableView, the corresponding zip file is unzipped and extracted in a temporary directory(newFilePath in my case). The contents unzipped is listed in the next tableView. When I touch the back button, the contents in the directory is listed again.

For example, consider that I have four zip files in my document directory.

songs.zip, videos.zip, files.zip, calculation.zip

When I run the application, all the four files are listed in the tableView. When I touch songs.zip, this file is extracted in the newFilePath and its contents are pushed to the next tableView. When I touch back, the previous tableView, i.e, the four files in the document directory are listed again. Everything works perfect.

The problem is, the extracted files in the newFilePath remains there itself. They occupy the memory unnecessarily. I want them to be removed from that path when I touch the back button, i.e, I want to make newFilePath empty when the back button is touched.

I tried for it. But, no use. I tried removeItemAtPath: method in viewWillAppear: and also in viewWillDisappear:. But it didnt work in both the cases.

Is there any other method to track the action of the back button? I want an event to take place when the back button is touched. So please help me by sharing开发者_运维问答 your ideas. Here is my code for your verification.

This is my 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];

Thank you for your answers.


Oh ya, thats quite simple:

in LoadView,

    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] 
                                            initWithTitle:@"Back" 
                                                    style:UIBarButtonItemStylePlain 
                                                   target:self 
                                                   action:@selector(backButtonHit)];

-(void)backButtonHit
{
// removeItemAtPath: newFilepath stuff here
  [self.navigationController popViewControllerAnimated:YES];
}
0

精彩评论

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

关注公众号