標籤:dict turn rect mat led 緩衝 計算 Dimension 不必要
tableView計算完高度後,把高度緩衝起來,避免下次重複計算,以減少不必要的消耗
// 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高度緩衝