2014-03-30 3 views
0

특정 테이블에서 이미지를 다운로드하도록 구문 분석 데이터베이스에 쿼리하고 있습니다. 내가 생각하는 것이 결함 인 것을 제외하고는 모든 것이 작동하고 있습니다.이미지가 아래로 스크롤 될 때까지 TableViewCells에 표시되지 않습니다.

이미지는 UITableView을 약간 스크롤 할 때만 나타납니다.

예 이미지를 비동기식으로 다운로드하고 있습니다.

건배

UPDATE 이미지가 메모리를 많이 사용하는 경우 내가

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Post"; 
    FeedPhotoCell *feedPhotoCell = (FeedPhotoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    WallImage *wallImage = [DataStore instance].wallImages[indexPath.row]; 

    [feedPhotoCell.photoPost setImage:wallImage.image]; 

    NSString *facebbokUserID = wallImage.fbID; 
    NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large",facebbokUserID]; 
    NSURL *facebookProfilePicURL = [NSURL URLWithString:urlString]; 

    [feedPhotoCell.profilePhoto setImageWithURL:facebookProfilePicURL]; 
    feedPhotoCell.profilePhoto.layer.cornerRadius = 10.0; 
    feedPhotoCell.profilePhoto.layer.borderColor = [UIColor orangeColor].CGColor; 
    feedPhotoCell.profilePhoto.layer.borderWidth = 1.0; 
    feedPhotoCell.profilePhoto.clipsToBounds = YES; 

    NSLog(@"image cell height: %f", feedPhotoCell.photoPost.image.size.height); 

    return feedPhotoCell; 
} 
+1

가능한 경우 이미지를 다운로드하고 표시하는 데 사용하는 코드를 제공하는 것이 도움이됩니다. – Brian

+1

배경 스레드에 이미지를 설정하는 것처럼 들립니다. 'imageView.image = ... '를 주 스레드에 보내서 테이블 뷰가 다시 그려지기 전에 변경 사항을 적용해야 할 수도 있습니다. – Eagerod

+0

나는 당신이 말한대로 그것을 고쳤습니다. cellForRowAtIndex에서 이미지를 다운로드하기 시작하고 응답이 오면 이미지를 메인 스레드에로드합니다. 감사합니다. – Camus

답변

0

을 이미지를 표시 여기

PFQuery *imageQuery = [PFQuery queryWithClassName:@"WallImageObject"]; 
    //[imageQuery orderByAscending:@"createdAt"]; 
    [imageQuery whereKey:@"geoPoint" nearGeoPoint:currentLocationInGeoPoint withinKilometers:3.0]; 
    NSLog(@"PFGeoPoint current location: %f and %f", currentLocationInGeoPoint.latitude, currentLocationInGeoPoint.longitude); 
    [imageQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){ 
     if (error) 
     { 
      NSLog(@"Error retreiving images: %@", error.localizedDescription); 
     }else 
     { 
      for (PFObject *wallImageObject in objects) { 
       WallImage *wallImage = [[WallImage alloc] init]; 
       wallImage.fbID = wallImageObject[@"UserId"]; 
       wallImage.username = wallImageObject[@"userName"]; 
       wallImage.createdAt = wallImageObject.createdAt; 

       [[NSOperationQueue pffileOperationQueue]addOperationWithBlock:^{ 
        wallImage.image = [UIImage imageWithData:[(PFFile *)wallImageObject[@"image"] getData]]; 
        [[NSNotificationCenter defaultCenter]postNotificationName:N_ImageDownloaded object:nil]; 
       }]; 

       wallImage.imageID = wallImageObject.objectId; 
       wallImage.geoPoint = wallImageObject[@"geoPoint"]; 
       NSLog(@"Image latitude: %f and londitude %f", wallImage.geoPoint.latitude, wallImage.geoPoint.longitude); 
       [[DataStore instance].wallImages addObject:wallImage]; 
      } 
      NSLog(@"%lu images in this location", (unsigned long)[[DataStore instance].wallImages count]); 
      if ([delegate respondsToSelector:@selector(communicationDidGetWallImages:)]) { 
       [delegate communicationDidGetWallImages:YES]; 
      } 
     } 

그리고, 그들은에 제거됩니다 메모리를 확보하십시오.

그런 다음 테이블보기에서 그리기를 시도하면 다시 다운로드해야하므로 시간이 오래 걸립니다.

해결책은 이미지를 전화로 디스크로 다운로드 한 다음 디스크의 파일에서 이미지를로드하는 것입니다.

+0

데이터가 다시로드되는 것과 다릅니다. 테이블을 전혀 스크롤하지 않으면 이미지가 나타나지 않습니다. 그러나 테이블을 약간 스크롤하면 이미지가 표시됩니다. – Camus

관련 문제