简体   繁体   English

Facebook iOS SDK FBProfilePictureView无法获取或显示图像

[英]Facebook iOS SDK FBProfilePictureView not fetching or displaying image

I have the following code in my View Controller 我的View Controller中有以下代码

if (FBSession.activeSession.isOpen) {
    [[FBRequest requestForMe] startWithCompletionHandler:
     ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
         if (!error) {
             self.nameString = user.name;
             self.profileImage.profileID = [user objectForKey:@"id"];
             [self.tableView reloadData];
         }
     }];
}

And I'm experiencing two issues. 我遇到了两个问题。 The first is that the profile image is never fetched and displayed. 首先是永远不会获取和显示个人资料图像。 The second is that I have to [self.tableView reloadData] in order for the name to show up. 第二个是我必须[self.tableView reloadData]以便显示名称。 This causes an ugly lag. 这会导致难看的滞后。 How do I fix both? 我该如何解决?

I do not know why your profile image is not fetched, but I had a problem with some profile images not being displayed and it lead me to write a modified version of the FBProfilePictureView which is here . 我不知道为什么未提取您的个人资料图像,但是我遇到了一些无法显示的个人资料图像的问题,这导致我编写了FBProfilePictureView的修改版本,该文件位于此处 This has a completion handler that gets called with error details if the download fails. 它有一个完成处理程序,如果下载失败,则会调用该处理程序并显示错误详细信息。 (In my case I believe the problem was that I sent out too many requests in a short period and my firewall blocked some of them). (就我而言,我认为问题在于我在短时间内发出了太多请求,但防火墙阻止了其中一些请求)。

As for having to reload the whole table, it depends where you are showing it. 至于必须重新加载整个表,则取决于您在何处显示它。 I assume in a cell? 我假设在牢房里? If so then when you are creating the cell, do: 如果是这样,那么在创建单元格时,请执行以下操作:

    CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    if (FBSession.activeSession.isOpen) {
        [[FBRequest requestForMe] startWithCompletionHandler:
            ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
                   if (!error) {
                         cell.profileImage.profileID = user.id;
                   }
             }];
    }

Also, just to note you can use user.id and user.name to access the results of the requestForMe query. 另外,仅需注意,您可以使用user.iduser.name来访问requestForMe查询的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM