- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? ? ? ? ?NSNumber *height = [self.heightAtIndexPath objectForKey:indexPath];
? ? ? ? ? ?if (height)
? ? ? ? ? ?{
? ? ? ? ? ? ? ? return height.floatValue;
? ? ? ? ? ?}
? ? ? ? ? ?else
? ? ? ? ? {
? ? ? ? ? ? ? ? return 100;
? ? ? ? ? ?}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? ? ? ? ? ? ?return UITableViewAutomaticDimension;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? ? ? ? ? ? NSNumber *height = @(cell.frame.size.height);
? ? ? ? ? ? ? ?[self.heightAtIndexPath setObject:height forKey:indexPath];
}
其中self.heightAtIndexPath是自己聲明的屬性 ? 用來(lái)緩存高度用的。
詳細(xì)請(qǐng)了解? http://www.reibang.com/p/64f0e1557562