2013-10-17 2 views
0

JSON 파일에서 일부 이미지와 문자열을 구문 분석 할 때 구문 분석이 제대로 작동하지만 이미지로드가 매우 느립니다. 나는 UITableViewCell을 눌렀을 때 UITableView가 내용을 더 빠르게 보여 주었다. 누구든지 그 문제를 알고 있습니까?UITableViewCell 데이터로드 오류

내가 사용하는 코드는 다음과 같습니다. NSOperationQueue를 사용하여 CPU 사용량을 낮게 유지합니다.

NSDictionary *dict; 
    dict = [application objectAtIndex:indexPath.row]; 

    name = [dict objectForKey:@"name"]; 
    detileName = [dict objectForKey:@"detailName"]; 
    itmsLink = [dict objectForKey:@"itms-serviceLink"]; 
    icon = [dict objectForKey:@"icon"]; 
    developer = [dict objectForKey:@"developer"]; 
    version = [dict objectForKey:@"version"]; 
    category = [dict objectForKey:@"category"]; 
    rating = [dict objectForKey:@"rating"]; 
    ratingNumbers = [dict objectForKey:@"ratingNumber"]; 
    description = [dict objectForKey:@"description"]; 
    developerEmails = [dict objectForKey:@"developerEmail"]; 

    [downloadQueue addOperationWithBlock:^{ 

     cell.AppName.text = name; 
     cell.category.text = category; 
     cell.rater.text = [NSString stringWithFormat:@"(%@)", ratingNumbers]; 
     if ([rating intValue] == 1) { 
      cell.rating.image = [UIImage imageNamed:@"1.png"]; 
     } 
     if ([rating intValue] == 2) { 
      cell.rating.image = [UIImage imageNamed:@"2.png"]; 
     } 
     if ([rating intValue] == 3) { 
      cell.rating.image = [UIImage imageNamed:@"3.png"]; 
     } 
     if ([rating intValue] == 4) { 
      cell.rating.image = [UIImage imageNamed:@"4.png"]; 
     } 
     cell.itms = itmsLink; 
     cell.AppIcon.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:icon]]]; 
     cell.number.text = [NSString stringWithFormat:@"%li", (long)indexPath.row + 1]; 
    }]; 

답변

0

그것은 이미 대부분의 데이터를 가지고 같은 당신이 AppIcon.image에 갈 것 이미지를 제외하고, 셀을 제시해야 보인다. 이제 상황이 설정되고 이미지 다운로드로 인해 셀이 즉시 표시되지 않습니다. 내 생각 엔 이미지 다운로드가 결국 완료되지만 다운로드가 완료된 후 셀을 다시 그려야하는 것은 아닙니다. 셀을 두드리면 그 자체가 다시 그려지기 때문에 이것이 아마 당신이 묘사 한 행동을 보는 이유 일 것입니다.

이미 다운로드 한 데이터를 사용하여 셀을 즉시 제시하고 이미지의 배경 다운로드를 시작하는 것이 좋습니다. 다운로드가 완료되면 NSNotification을 보내고 해당 셀을 업데이트 할 수 있습니다. 초기화하는 동안 URL을 받아들이는 NSOperation의 하위 클래스를 생성 한 다음 작업 대기열에 해당 op를 추가하여 수행 할 수 있습니다.

자신이 모두 작동하지 않으려면 UIImageView에 범주가 있습니다. AFNetworking을 사용하여 블록을 사용하여 업데이트를 수행합니다. @Nick Galasso에서 언급 한 바와 같이 https://github.com/zbowling/AFNetworkingPollTest/blob/master/ServerTest/UIImageView%2BAFNetworking.h

0

- 당신이 새로 고쳐지지 않는 세포의과 UITableView 실제로 재사용 셀의 다운로드가 완료되면 다시 셀 포인터를 받아야하기 때문에 블록에 셀 포인터를 전달하는 것은 아주 나쁜 방법입니다 - 실제로는 NSIndexPath의 대상이 아니라 셀에 관심이 있습니다. 링크에서

: 당신은 게으른 이미지 로딩에 완벽한 샘플 코드를 찾을 수 있습니다 https://developer.apple.com/library/ios/samplecode/LazyTableImages/Introduction/Intro.html

이, 조각 아래 실제로보기를 가져 오는 부분을 표시, 설정 다운로드 마무리 호출이 코드는 이미지가 최대한 빨리이다 :

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; 
cell.imageView.image = downloadedImage; 

클래스를 다운로드하는 일부 완료 핸들러에서 호출 할 수 있습니다 (Apple 링크의 샘플에서 해당 샘플을 볼 수 있습니다).