2
我做的UITableView单元格高度(动态高度),按照UIImageView的高度,目前它的工作不错,但我的问题是UITableView的不顺畅滚动或不能正常工作,如果我快速度滚动的UITableView细胞高度为每幅图像的问题
我认为问题是我重新加载tableview单元格中的行,所以tableview滚动不起作用任何人都可以告诉我这个问题的任何好建议?
这里我做了什么
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Create the cell...
[cell.myImageView setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if (image != nil) {
[self.images insertObject:image atIndex:indexPath.row];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:YES];
}
}];
return cell;
}
为了设置高度为每幅图像
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
id image = [self.images objectAtIndex:indexPath.row];
if ([image isKindOfClass:[NSNull class]]) {
return defaultHeight;
} else {
return [image size].height + topPadding + bottomPadding;
}
}
为什么要重载UITableViewCell?另外,你是否正在使用AFNetworking等网络库? –
是的,我是usin AFNetworking和SDWebimage我重新加载行,因为我需要根据UIIMageview高度设置uitableview单元格高度@KunalKShah –
@MayankPatel我最近检查了您使用的第三方,它设法异步下载。 –