TableView after calculating the height, cache the height to avoid the next repeat calculation to reduce unnecessary consumption
// declare cellHeightsDictionaryNSMutableDictionary *cellHeightsDictionary; // initialize in code (thanks to @Gerharbo)cellHeightsDictionary = @{}.mutableCopy; // declare table dynamic row height and create correct constraints in cellstableView.rowHeight = UITableViewAutomaticDimension; // save height- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [cellHeightsDictionary setObject:@(cell.frame.size.height) forKey:indexPath];} // give exact height value- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { NSNumber *height = [cellHeightsDictionary objectForKey:indexPath]; if (height) return height.doubleValue; return UITableViewAutomaticDimension;}
IOS TableView Height Cache