0

我正在使用https://github.com/mattconnolly/ZipArchive循环解压缩文件。问题在于解压缩循环我无法更新我的标签。我的代码:

-(void) UnzipFiles
{

for (int i=0; i < zippedFiles.count; i++)
{

    [lb7 setText:[NSString stringWithFormat:@"Unziping file %d/%d",i+1,zippedFiles.count]]; //not working


      NSString *zipFilePath = [documentsDirectory stringByAppendingPathComponent:[zippedFiles objectAtIndex:i]];
      NSString *output = [documentsDirectory stringByAppendingPathComponent:[unzipFolders objectAtIndex:i]];

       NSLog(@"Unziping: %@ ",[zippedFiles objectAtIndex:i]);
       NSLog(@"To: %@",[unzipFolders objectAtIndex:i]);


      ZipArchive* za = [[ZipArchive alloc] init];

      if( [za UnzipOpenFile:zipFilePath] ) {

          if( [za UnzipFileTo:output overWrite:YES] != NO )
          {
            NSLog(@"Unziped %@ ",[zippedFiles objectAtIndex:i]);
          }

          [za UnzipCloseFile];
          [self deleteFile:[zippedFiles objectAtIndex:i]];
      }
      else
      {
        NSLog(@"The file %@ not exist",[zippedFiles objectAtIndex:i]);

      }
    doneBtn.hidden = NO;
    [lb7 setText:@""];


  }
}
4

1 回答 1

2

在后台任务中进行解压缩并将 UI 更新分派到主线程:

-(void) UnzipFiles
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        for (int i=0; i < zippedFiles.count; i++) {
            ⋮
            dispatch_async(dispatch_get_main_queue(), ^{
                lb7.text = …;
            });
        }
    });
}
于 2013-07-14T08:00:09.760 回答