# UITableView-FDTemplateLayoutCell: A Cache-First Approach to Auto Layout Cell Heights

> This Objective-C library automates UITableViewCell height calculation using template cells. Its real value is the caching layer, which reduces the extra height calls that iOS 8 introduced.

**forkingdog/UITableView-FDTemplateLayoutCell** — GitHub describes it as Template auto layout cell for automatically UITableViewCell height calculating. The repository metadata lists Objective-C as its primary language. The metadata lists the MIT license. This article stays within the project description and details documented in the GitHub repository README.

- Repository: https://github.com/forkingdog/UITableView-FDTemplateLayoutCell
- Stars: 9,852 · Forks: 1,984
- Language: Objective-C
- License: MIT
- Published: 2026-08-13 · Updated: 2026-08-18 · Language: en
- Canonical page: https://hysenlabs.com/projects/forkingdog-uitableview-fdtemplatelayoutcell

## The Problem It Solves: Redundant Height Calculations on iOS 8

Before iOS 8, UITableView required explicit row heights. Auto Layout made it possible to compute heights from constraints, but the system called heightForRowAtIndexPath far more often than needed, especially during scrolling. This library attacks that problem directly. It is for Objective-C developers who have cells that are self-satisfied, meaning Auto Layout constraints pin every edge (top, left, bottom, right) of the content view. The README is explicit: a bad cell is one missing right and bottom constraints. So the target user is someone who already builds constraint-complete cells and wants to avoid manual height math. The library does not handle the case where you have ambiguous layout; it assumes you have done the Auto Layout work correctly.

## How It Works: Template Cells and Two Height Modes

The mechanism is a category on UITableView. You call fd_heightForCellWithIdentifier:configuration: inside heightForRowAtIndexPath. The library dequeues a template cell using the same identifier you registered, applies your configuration block, and then asks for its height. The README describes two modes. Auto layout mode uses systemLayoutSizeFittingSize:. Frame layout mode uses sizeThatFits:. The library chooses automatically based on whether your cell has Auto Layout constraints on the content view. You can force frame mode with cell.fd_enforceFrameLayout = YES, but then you must override sizeThatFits: in your cell and return the content view height, separator excluded. This is a clear separation of concerns: the library handles the measurement plumbing, you handle the cell's internal layout logic.

## Getting It Running: Commands and Configuration Keys

Installation is via CocoaPods. The README gives pod search UITableView+FDTemplateLayoutCell and pod setup if the search fails. The latest version listed is 1.6. Import the header UITableView+FDTemplateLayoutCell.h. The basic call is one line inside heightForRowAtIndexPath. You must register the cell identifier first, either via a storyboard prototype cell, registerNib:forCellReuseIdentifier:, or registerClass:forCellReuseIdentifier:. The README warns that a template cell is created by dequeueReusableCellWithIdentifier:, so registration is mandatory. Debug logging is a boolean property you set on the table view: self.tableView.fd_debugLogEnabled = YES. The logs show calculate, precached, and hit cache events, which is useful for verifying that caching actually works.

## The Caching APIs: Index Path and Key-Based Caches

The basic API recalculates every time. The README notes that on iOS 8, heightForRowAtIndexPath gets called more often than expected, so extra calculations happen during scrolling. That is why the library offers two caching variants. The first is cacheByIndexPath:, which stores heights per NSIndexPath. The second is cacheByKey:, which takes a unique identifier from your entity, such as entity.uid. The key-based cache is more robust when rows move or are inserted, because an index path cache can return stale heights after a row changes position. The README release notes mention that version 1.2 added precache and auto cache invalidation. This suggests the library proactively calculates heights for nearby rows and invalidates entries when the table view changes. The README does not specify the invalidation trigger precisely, so you should test it with your own data mutations.

## A Real Limitation: The Self-Satisfied Cell Requirement

The library only works correctly if your cell is fully self-satisfied. The README shows a diagram where a missing right or bottom constraint makes a cell bad. That means you cannot use this library as a crutch for incomplete Auto Layout. If your cell relies on sizeThatFits: with manual frame layout, you must override that method and return the exact height, otherwise the measurement will be wrong. Another limitation is that the template cell is dequeued and configured each time, which creates an overhead. The caching APIs mitigate that, but the first calculation for a new index path still requires a full layout pass. For extremely complex cells, that first pass can be expensive. The README does not mention any performance numbers, so you cannot assume it is fast; you have to measure it in your own context.

## The Alternative: iOS 8 Self-Sizing Cells and Modern UITableView

Apple introduced self-sizing cells in iOS 8 with estimatedRowHeight and UITableViewAutomaticDimension. That built-in mechanism also uses Auto Layout, but it does not provide a caching API. The library's advantage is the explicit cacheByKey: mode, which the system does not offer. The trade-off is that the library is Objective-C only and targets an older iOS generation. On iOS 11 and later, UITableView automatic dimensioning is more mature and often sufficient. If you are starting a new project in Swift, you would likely use the system API instead. The library is a tool for existing Objective-C codebases where you need fine-grained control over when heights are recalculated. The README does not mention Swift interoperability, so assume you would need a bridging header or a Swift wrapper.

## Maintenance and License: A Stale but Stable Utility

The repository is archived? No, the metadata says archived: no, but last push is unknown and recent releases are none. The README lists release 1.6 as the latest, with a bug fix for iOS 10. That was years ago. The library has not seen recent activity, which is a double-edged sword. On one hand, it is stable and unlikely to break because it does a narrow job. On the other hand, it does not support newer iOS features or Swift. The license is MIT, so you can fork it and patch it yourself. The release notes show a history of bug fixes, including iOS 10 issues, so you should check if your deployment target is affected. The codebase is small, so maintenance cost is low if you need to make changes. But do not expect upstream support for new UIKit behaviors.

## Conclusion

Adopt this library if you maintain an Objective-C codebase with self-sizing Auto Layout cells and want to cut redundant height calculations without rewriting your cell configuration. Skip it if you are on Swift with iOS 11 or later, where UITableView automatic dimensioning and estimated heights may suffice. Before adopting, verify the 1.6 release fixes the iOS 10 bug you care about, confirm your cells are fully self-satisfied with constraints on all four edges, and test the cache invalidation behavior when your models mutate. The library is a pragmatic fix for a specific iOS 8-era pain, not a general layout solution.

## FAQ

### How do I install UITableView-FDTemplateLayoutCell?

Through CocoaPods, with `pod search UITableView+FDTemplateLayoutCell`. If the search does not surface the latest version, the README says to run `pod setup` and search again. The version it calls latest is 1.6.

### Why is the height wrong when I use FDTemplateLayoutCell in frame layout mode?

In frame layout mode you must override -sizeThatFits: and return the content view's height with the separator excluded, and the README's sample returns a sum written out by hand. Any subview you add has to be added to that expression yourself, or the row keeps its old height.

### Is UITableView-FDTemplateLayoutCell still updated for new iOS versions?

The default branch received its last push on 2022-03-07 and the repository has no GitHub releases. The version the README names as latest is 1.6, and the release note for it is a fix for a bug in iOS 10.

## Sources

- [Official README](https://github.com/forkingdog/UITableView-FDTemplateLayoutCell#readme)
- [Project repository](https://github.com/forkingdog/UITableView-FDTemplateLayoutCell)
- [README](https://github.com/forkingdog/UITableView-FDTemplateLayoutCell/blob/master/README.md)
- [Releases](https://github.com/forkingdog/UITableView-FDTemplateLayoutCell/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/forkingdog-uitableview-fdtemplatelayoutcell
