2013-07-14 2 views
0

https://github.com/mattconnolly/ZipArchive을 사용하여 루프에서 파일을 압축 해제하고 있습니다. 압축 해제 루프에 문제가 있습니다. 레이블을 업데이트 할 수 없습니다. 내 코드 :UI 업데이트 스레딩에서 setText가 작동하지 않습니다.

-(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:@""]; 


    } 
} 
+1

당신은 백그라운드 스레드에서이 일을하고 있는가? 그렇다면 UI 업데이트가 주 스레드에서 발생해야합니다. –

+0

사이드 노트 : 새로운 요소 액세스 구문 인'zippedFiles [i]'를 사용하면 더욱 행복해집니다. –

답변

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 = …; 
      }); 
     } 
    }); 
} 
관련 문제