在UITableViewCell中显示登录用户的FB配置文件Pic

时间:2012-08-28 11:05:32

标签: iphone facebook facebook-graph-api uitableview uiimage

我是facebook整合的新手。在我经历了这么多教程之后,我从facebook SDK中了解了一些东西。

请帮我解决这个问题。

- (void)apiGraphMe
{
 currentAPICall = kAPIGraphMe;
 AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
 NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"name,picture",  @"fields",
                               nil];
 [[delegate facebook] requestWithGraphPath:@"me" andParams:params andDelegate:self];
}

- (void)request:(FBRequest *)request didLoad:(id)result
{
NSLog(@"result is------------%@",result);
if ([result isKindOfClass:[NSDictionary class]])
{
    NSLog(@"id is: %@", [result objectForKey:@"id"]); 
    NSString *idValue = [result objectForKey:@"id"];
}
}

在上面的代码中我得到了loggedIn用户个人资料pic的URL。我的愿望是将url图像显示在tableView单元格中。

我认为将url图像直接传递给tableview cell的imageview是不正确的方法。如果
我们根据我们可以获取个人资料照片来传递用户的ID。因为如果其他用户登录,它会降低复杂性。

希望您了解问题和背景。如果有任何语法或英语错误,请原谅我。

非常感谢您提前获得任何帮助和回复。

1 个答案:

答案 0 :(得分:4)

以下是在tableview中显示用户/朋友个人资料图片的步骤

  • 您已拥有用户/朋友ID

  • 声明IBOutlet FBProfilePictureView * userProfileImage; //确保导入FacebookSDK / FacebookSDK.h

  • 在您的IB / Storeyboard tableview单元格中
  • ,拖动UIView(宽36,高36)

  • 更改此uiview的类(在身份检查器中更改为FBProfilePictureView)

  • 将上面的iboutlet连接到此FBProfilePictureView

  • 在cellForRowAtIndexPath中
  • ,按以下方式分配图像

  • (UITableViewCell *)tableView:(UITableView *)tableView      cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString * CellIdentifier = @“FriendsCell”;

    FriendsCell cell =(FriendsCell )[tableView                                            dequeueReusableCellWithIdentifier:CellIdentifier];

    cell.userProfileImage.profileID = objUD.userID; 返回细胞; }

注意:我假设您有一个名为FriendsCell的自定义UITableViewCell类

在viewDidLoad方法中,写下以下行     [FBProfilePictureView类];