我有一个显示 Facebook 好友列表的 tableView。我在单元格中有一个图像视图,它显示用户的 profilePicture。使用 AFNetworking 我调用新图像并在加载时放置一个占位符。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"FbFriendCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
if (tableView == self.searchDisplayController.searchResultsTableView) {
NSDictionary *friend = (NSDictionary *)[self.searchResults objectAtIndex:indexPath.row];
cell.textLabel.text = [friend valueForKey:@"name"];
} else {
NSDictionary *friend = [[self.sections valueForKey:[[[self.sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
UIImageView *profilePic = (UIImageView *)[cell.contentView viewWithTag:10];
UILabel *displayName = (UILabel *)[cell.contentView viewWithTag:20];
UIButton *playButton = (UIButton *)[cell.contentView viewWithTag:30];
displayName.text = [friend valueForKey:@"name"];
UIImage *defaultPhoto = [UIImage imageNamed:@"person.png"];
NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", friend[@"id"]];
NSURL *avatarUrl = [NSURL URLWithString:urlString];
[profilePic setImageWithURL:avatarUrl placeholderImage:defaultPhoto];
profilePic.contentMode = UIViewContentModeScaleAspectFit;
}
这会导致 tableview 出现一些速度/性能问题。有谁知道为什么会这样,这个设置正确吗?
这些单元是使用情节提要创建的原型单元。我还有其他代码用于单元格中的其他对象,但是删除配置文件图片部分会使单元格正常执行,所以这似乎是问题所在,只是不知道为什么。
编辑
UIImage *defaultPhoto = [UIImage imageNamed:@"person40x40.png"];
NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?width=40&height=40", friend[@"id"]];
我已经更新了图片以适应 40x40 图像视图,但没有区别。iphone4 加载表格单元格的速度很慢。与滚动非常流畅的iphone5相比。
看起来 profilePic 是最糟糕的。这是因为来自 Facebook 的数据请求。我已将 profilePic 更改为仅不是 URL 请求的默认 Pic,并且表格视图很好。所以这显然是 setImageWithURL 的性能问题。
看看其他问题,这似乎是实现这一目标的最佳方式:-在 iOS 应用程序中管理 facebook 朋友图片的最佳实践
欢迎任何想法