【发布时间】:2017-02-23 10:34:46
【问题描述】:
我正在根据 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?
-
是的,我正在使用 AFNetworking 和 SDWebimage 我正在重新加载行,因为我需要根据 UIIMageview 高度 @KunalKShah 设置 uitableview 单元格高度
-
@MayankPatel 我最近检查过您正在使用第三方,它设法以异步方式下载。
-
@agent_stack 我没有图像问题,但我有单元格高度问题
-
对于表格的动态高度,在
heightForRowAtIndexPath中使用uitableviewautomaticdimension,并在estimatedHeightForRowAtIndexPath中写入一些预期的高度。
标签: ios objective-c uitableview uiimageview