Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将Facebook数据加载到表视图中_Ios_Objective C_Uitableview_Facebook Sdk 3.0 - Fatal编程技术网

Ios 将Facebook数据加载到表视图中

Ios 将Facebook数据加载到表视图中,ios,objective-c,uitableview,facebook-sdk-3.0,Ios,Objective C,Uitableview,Facebook Sdk 3.0,我一直在用正确的方法获取用户的所有Facebook好友,并将其加载到表视图中(我只想使用FBFriendPickerViewController,但它很难看,似乎你无法修复) 我想要的只是cell imageView中的配置文件图片和cell textLabel中的名称,就这么简单 使用NSURL/NSData不会裁剪图像,我更愿意使用FBProfilePictureView,因此请尝试在任何解决方案中使用它。谢谢 从Facebook获取数据 -(void)facebookOpenSession

我一直在用正确的方法获取用户的所有Facebook好友,并将其加载到表视图中(我只想使用FBFriendPickerViewController,但它很难看,似乎你无法修复)

我想要的只是cell imageView中的配置文件图片和cell textLabel中的名称,就这么简单

使用NSURL/NSData不会裁剪图像,我更愿意使用FBProfilePictureView,因此请尝试在任何解决方案中使用它。谢谢

从Facebook获取数据

-(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];
            }
        }];
    }
}
将数据配置到单元格中

- (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;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@“cell”forIndexPath:indexPath];
//配置单元格。。。
NSDictionary*friend=[self.facebookFriends对象索引:indexPath.row];
cell.textlab.text=friend.name;
NSURL*profilePictureUrl=[NSURL URLWithString:[NSString stringWithFormat:@]http://graph.facebook.com/%@/图片?类型=正常”,friend.id]];
NSData*profilePictureData=[NSData DATA with contentsofURL:profilePictureUrl];
cell.imageView.image=[UIImage imageWithData:profilePictureData];
返回单元;
}

人们是如何学习如何使用Facebook SDK制作所有这些东西的,我花了将近4个小时试图完成上面所述的工作,我觉得我完全错过了一些东西。

有几个开源库可以让下载图像变得简单。我最喜欢的是,但也有。使用其中一个类别,您的任务变得非常简单:

[myImageView setImageURL:"http://test.com/test.jpg"];
即使您不想使用这些库,也不要使用当前尝试的方式(即
[NSData dataWithContentsOfURL:profilePictureUrl]
)。我相信这是一个同步操作,它会阻塞您的UI。使用上面两个链接之一的代码,或创建自己的UIImageView类别