我在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];
}
}];
}
我遇到了两个问题。第一个是永远不会提取和显示配置文件图像。第二个是我必须[self.tableView reloadData]
才能显示名称。这导致了一个难看的滞后。我如何解决这两个问题?
答案 0 :(得分:1)
我不知道为什么你的个人资料图片没有被提取,但我有一些问题,一些个人资料图片没有被显示,这导致我写了一个修改版的FBProfilePictureView,here。这有一个完成处理程序,如果下载失败,将使用错误详细信息调用它。 (在我的情况下,我认为问题是我在短时间内发出了太多请求,我的防火墙阻止了其中一些请求。)
至于必须重新加载整个表格,这取决于你在哪里展示它。我假设在一个牢房?如果是,那么在创建单元格时,请执行以下操作:
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;
}
}];
}
另外,请注意,您可以使用user.id
和user.name
来访问requestForMe
查询的结果。