2014-04-14 2 views
1

나는 모든 사용자의 Facebook 친구들을 가져 와서 테이블 뷰에로드하려고합니다. (간단히 FBFriendPickerViewController를 사용하지만 추악하고 수정하지 못할 수도 있습니다. 그)Facebook 데이터를 테이블 뷰에로드 중

내가 원하는 건 셀 imageView의 프로필 사진과 셀 textLabel의 이름이다.

NSURL/NSData를 사용하면 이미지를 자르지 않습니다. Id는 FBProfilePictureView를 사용하므로 많은 솔루션에서 사용하십시오. 감사!

-(void)facebookOpenSession { 

    if (FBSession.activeSession.isOpen) { 
     [[FBRequest requestForMyFriends] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 

      if (error) { 
       // handle error 
      } else { 
       self.facebookFriends = [NSArray arrayWithArray:[result objectForKey:@"data"]]; 
       [[NSNotificationCenter defaultCenter] postNotificationName:@"facebookRequestForMyFriends" object:self]; 
      } 
     }]; 
    } 
} 

구성 데이터 셀에 페이스 북에서 데이터를 가져 사람들이 페이스 북 SDK와 모든 일을하는 방법을 배울 어떻게

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 

    // Configure the cell... 
    NSDictionary<FBGraphUser> *friend = [self.facebookFriends objectAtIndex:indexPath.row]; 
    cell.textLabel.text = friend.name; 

    NSURL *profilePictureUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=normal", friend.id]]; 

    NSData *profilePictureData = [NSData dataWithContentsOfURL:profilePictureUrl]; 

    cell.imageView.image = [UIImage imageWithData:profilePictureData]; 

    return cell; 
} 

, 내가 무엇을하려고 약 4 시간 소요 위에서 설명한 바와 같이 나는 뭔가를 완전히 놓친 것처럼 느낍니다.

답변

0

이미지를 쉽게 다운로드 할 수있는 여러 오픈 소스 라이브러리가 있습니다. 내가 좋아하는 것은 이지만, 역시 SDWebImage이있다. 당신이이 라이브러리를 사용하지 않는 경우에도, 그것을 당신은 그것을 시도하고있는 방법 (즉, [NSData dataWithContentsOfURL:profilePictureUrl]을)하지 않는다

[myImageView setImageURL:"http://test.com/test.jpg"]; 

: 이러한 범주 중 하나를 사용하여, 당신의 임무는 다음과 같이 간단하게된다. 나는 그것이 귀하의 UI를 차단 동기 작업이라고 생각합니다. 위의 2 개 링크 중 하나의 코드를 사용하거나 자신의 UIImageView 카테고리를 만드십시오.

관련 문제