0
votes

I'm using the popular class calle SSZipArchive to unzip a file, concretely this method:

+ (BOOL)unzipFileAtPath:(NSString *)path toDestination:(NSString *)destination progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError *error))completionHandler

And I'm updating two uilabels text in the blocks inside, both of them are allocated, both of their texts are changed before, when I print the content of the uilabels the text is updated but the screen doesn't update it, I have to say that this method is loaded when I finish the download of a zip into a delegate method.

My code:

- (void)downloadManager:(id)sender finishedDownload:(ANDownload *)download {  
    if ( [[NSFileManager defaultManager] fileExistsAtPath:download.storeFile] ) {
      NSLog(@"Download exists");
      [self.labelStep setText:CustomLocalizedString(@"ZIP_DECOMPRESSING_MSG", nil)];

      [SSZipArchive unzipFileAtPath:download.storeFile toDestination:self.saveFolderPath progressHandler:^(NSString *entry, unz_file_info zipInfo, long entryNumber, long total) {
          //Your main thread code goes in here
          NSString * labelProgressText = [NSString stringWithFormat:@"%ld / %ld", entryNumber, total];
          self.labelProgress.text = labelProgressText;
       } completionHandler:^(NSString *path, BOOL succeeded, NSError *error) {
         NSLog(@"Succeeded %d in path: %@", succeeded, path);
         if(succeeded){
         .....
1
Show your code, not unzipFileAtPath:... method signature. How do you use it? Post as much related code as possible ... - zrzka
Do you update the label in if (succeed) {...}? - sbarow
No, in the suceed I do some stuff and present another view controller... I update labelStep text and labelProgress text where you can see it... - peig

1 Answers

1
votes

You are probably not on the main thread, you can try this :

dispatch_async(dispatch_get_main_queue(), ^{
    //Your main thread code goes in here
    yourLabel.text = @"new text";       
});

EDIT

Since you are on the main thread, and you want to update your labels right away you would need this :

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    dispatch_async(dispatch_get_main_queue(), ^{
        //Your main thread code goes in here
        yourLabel.text = @"new text";       
    });
}

However, i don't understand why it is not updated at the end of your method in your example. There might be a better solution.