2014-07-21 2 views
0

파노라마를 표시하기 위해 panoramaGL 프레임 워크를 사용하려고합니다. 서버 측은 큐브 파노라마의 모든면에 대해 여러 타일 이미지를 반환합니다. 그래서 배열에 asyncroniously이 이미지를로드해야하고이 후 나는이 이미지에서 큰 측면 질감을해야 -이 작업의 첫 번째 부분에 대한 코드는 다음과 같습니다GCD를 사용하여 배열에 이미지를 비동기 적으로로드하십시오.

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ 

    int columnCount; 
    int rowCount; 

    NSString *side; 

    if ([level isEqual: @"3"]) { 
     columnCount = 1; 
     rowCount = 1; 
    } else if ([level isEqual: @"2"]) { 
     columnCount = 2; 
     rowCount = 2; 

... 여기에 내가 준비 내가 이해하는 방법, 내 배열이로드되었는지 - - 그리고 지금 재치를 작동 할 수있는 URL 문자열은

if (face == PLCubeFaceOrientationFront) 
     side = @"F"; 
    else if (face == PLCubeFaceOrientationBack) 
     side = @"B"; 

가 ... 여기에 내가

self.tileArray = [[NSMutableArray alloc] initWithCapacity:columnCount]; 

    for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) { 
     for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { 

      NSString *tileUrl = [NSString stringWithFormat:@"%d_%d", columnIndex, rowIndex]; 

      NSMutableArray *tileUrlComponents = [NSMutableArray array]; 

      [tileUrlComponents addObject: panoramaData[@"id"]]; 
      [tileUrlComponents addObject: side]; 
      [tileUrlComponents addObject: level]; 
      [tileUrlComponents addObject: tileUrl]; 

      NSString *tileIdString = [tileUrlComponents componentsJoinedByString:@"/"]; 

      NSString *panoramaIdUrlString = [NSString stringWithFormat:@"http://SOMEURL=%@", tileIdString]; 

      NSURL *url = [NSURL URLWithString:panoramaIdUrlString]; 
      NSURLRequest *req = [NSURLRequest requestWithURL:url]; 

      [NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *res, NSData *data, NSError *err) { 
       UIImage *image = [UIImage imageWithData:data]; 
       dispatch_async(dispatch_get_main_queue(), ^{ 
        NSMutableArray *array = [self.tileArray objectAtIndex:columnIndex]; 
        [array replaceObjectAtIndex:rowIndex withObject:image]; 
        [self.tileArray addObject:array]; 
       }); 
      }]; 

      NSLog(@"The URL for the %@ tile is %@", tileUrl, tileIdString); 
     } 
    } 
}); 

주요 질문은 URL 문자열 매개 변수를 준비 매개 변수 그 안에있는 이미지들. 두 번째 질문은 이제 불행히도 빈 배열을 얻는다는 것입니다. 어떤 도움이 필요합니까?

+0

이 질문에 대한 답을 살펴보십시오 시도를 제공합니다 - http://stackoverflow.com/questions/24857150/the-program-f low-going-wrong/24857220? noredirect = 1 # comment38602097_24857220 동일한 기술을 사용해야합니다. 디스패치 그룹을 사용하여 모든 비동기로드가 완료된시기를 알 수 있습니다. – Paulw11

답변

0

나는 당신이 조작을 고려해 왔는지 확신하지 못합니다.

이것은 내가 얼마나입니다 :

  1. 는 각 요청에 대해 NSOperation 만들기
  2. NSOperationQueue 각 작업을 추가 (이로드가 완료 될 때까지 작업이 살아 유지 코드에서 확인). (-operations을 호출하면 진행중인 작업 수를 알 수 있습니다.
  3. NSOperationQueue을 역 스레드에 구현하면 -waitUntilAllOperationsAreFinished (이 방법은 모든 이미지를 다운로드 할 때까지 현재 스레드를 차단 함)을 사용하여 이미지를 표시하는 코드를 실행합니다 . 당신 또는 당신이

    dispatch_queue_t 큐 = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_HIGH, 0ul)과 같은 작업을 수행 할 수 있습니다 -(void)addOperations:(NSArray *)ops waitUntilFinished:(BOOL)wait

0

를 사용하여 NSOperationQueueNSArray 모든 NSOperation's를 추가하고 추가 할 수 있습니다; dispatch_async (큐,^{IMAGEPATH이 directory..You이 임시 디렉토리를 만들고 거기에 이미지를 저장 ... 그리고 검색하는 동안 당신은 그냥 간단한 방법을 사용할 수 있습니다 응용 프로그램에서 경로 아이오와

 dispatch_sync(dispatch_get_main_queue(), ^{ 

      NSData *data = [[NSData alloc] initWithContentsOfURL: ImageURL]; 
      UIImage *image = [[UIImage alloc] initWithData: data]; 


      [UIImageJPEGRepresentation(image, 100) writeToFile: imagePath atomically: YES]; 


     }); 
    }); 

..

있는 UIImage * 이미지 = [있는 UIImage imageWithCOntentsOFFile : IMAGEPATH] ;. 그것은 나를 위해 일한

... 단지

관련 문제