{"id":1275,"url":"https://github.com/forkingdog/UITableView-FDTemplateLayoutCell","last_synced_at":"2025-07-30T20:33:15.575Z","repository":{"id":30502279,"uuid":"34056623","full_name":"forkingdog/UITableView-FDTemplateLayoutCell","owner":"forkingdog","description":"Template auto layout cell for automatically UITableViewCell height calculating","archived":false,"fork":false,"pushed_at":"2022-03-07T10:01:30.000Z","size":4257,"stargazers_count":9943,"open_issues_count":129,"forks_count":2012,"subscribers_count":331,"default_branch":"master","last_synced_at":"2024-05-22T03:01:40.891Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/forkingdog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-16T13:14:19.000Z","updated_at":"2024-05-20T21:15:11.000Z","dependencies_parsed_at":"2022-08-07T15:16:01.892Z","dependency_job_id":null,"html_url":"https://github.com/forkingdog/UITableView-FDTemplateLayoutCell","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forkingdog%2FUITableView-FDTemplateLayoutCell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forkingdog%2FUITableView-FDTemplateLayoutCell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forkingdog%2FUITableView-FDTemplateLayoutCell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/forkingdog%2FUITableView-FDTemplateLayoutCell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/forkingdog","download_url":"https://codeload.github.com/forkingdog/UITableView-FDTemplateLayoutCell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":220549858,"owners_count":16666275,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:42.725Z","updated_at":"2024-12-04T20:31:15.719Z","avatar_url":"https://github.com/forkingdog.png","language":"Objective-C","funding_links":[],"categories":["Layout","Objective-C","awesome-ios ##","9. 其他与展望","Objective-C  Stars 1000以内排名整理","Object-C 库","UI Components","iOS"],"sub_categories":["Other Hardware","Other free courses","5. 参考材料","ListView"],"readme":"# UITableView-FDTemplateLayoutCell\n\u003cimg src=\"https://cloud.githubusercontent.com/assets/219689/7244961/4209de32-e816-11e4-87bc-b161c442d348.png\" width=\"640\"\u003e\n\n## Overview\nTemplate auto layout cell for **automatically** UITableViewCell height calculating.\n\n![Demo Overview](https://github.com/forkingdog/UITableView-FDTemplateLayoutCell/blob/master/Sceenshots/screenshot2.gif)\n\n## Basic usage\n\nIf you have a **self-satisfied** cell, then all you have to do is: \n\n``` objc\n#import \"UITableView+FDTemplateLayoutCell.h\"\n\n- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath\n{\n    return [tableView fd_heightForCellWithIdentifier:@\"reuse identifer\" configuration:^(id cell) {\n        // Configure this cell with data, same as what you've done in \"-tableView:cellForRowAtIndexPath:\"\n        // Like:\n        //    cell.entity = self.feedEntities[indexPath.row];\n    }];\n}\n```\n\n## Height Caching API\n\nSince iOS8, `-tableView:heightForRowAtIndexPath:` will be called more times than we expect, we can feel these extra calculations when scrolling. So we provide another API with cache by index path:   \n\n``` objc\n- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {\n    return [tableView fd_heightForCellWithIdentifier:@\"identifer\" cacheByIndexPath:indexPath configuration:^(id cell) {\n        // configurations\n    }];\n}\n```\n\nOr, if your entity has an unique identifier, use cache by key API:\n\n``` objc\n- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {\n\tEntity *entity = self.entities[indexPath.row];\n    return [tableView fd_heightForCellWithIdentifier:@\"identifer\" cacheByKey:entity.uid configuration:^(id cell) {\n        // configurations\n    }];\n}\n```\n\n## Frame layout mode\n\n`FDTemplateLayoutCell` offers 2 modes for asking cell's height.  \n\n1. Auto layout mode using \"-systemLayoutSizeFittingSize:\"  \n2. Frame layout mode using \"-sizeThatFits:\"  \n\nGenerally, no need to care about modes, it will **automatically** choose a proper mode by whether you have set auto layout constrants on cell's content view. If you want to enforce frame layout mode, enable this property in your cell's configuration block:  \n\n``` objc\ncell.fd_enforceFrameLayout = YES;\n```\nAnd if you're using frame layout mode, you must override `-sizeThatFits:` in your customized cell and return content view's height (separator excluded)\n\n```\n- (CGSize)sizeThatFits:(CGSize)size {\n    return CGSizeMake(size.width, A+B+C+D+E+....);\n}\n```\n\n## Debug log\n\nDebug log helps to debug or inspect what is this \"FDTemplateLayoutCell\" extention doing, turning on to print logs when \"calculating\", \"precaching\" or \"hitting cache\".Default to \"NO\", log by \"NSLog\".\n\n``` objc\nself.tableView.fd_debugLogEnabled = YES;\n```\n\nIt will print like this:  \n\n``` objc\n** FDTemplateLayoutCell ** layout cell created - FDFeedCell\n** FDTemplateLayoutCell ** calculate - [0:0] 233.5\n** FDTemplateLayoutCell ** calculate - [0:1] 155.5\n** FDTemplateLayoutCell ** calculate - [0:2] 258\n** FDTemplateLayoutCell ** calculate - [0:3] 284\n** FDTemplateLayoutCell ** precached - [0:3] 284\n** FDTemplateLayoutCell ** calculate - [0:4] 278.5\n** FDTemplateLayoutCell ** precached - [0:4] 278.5\n** FDTemplateLayoutCell ** hit cache - [0:3] 284\n** FDTemplateLayoutCell ** hit cache - [0:4] 278.5\n** FDTemplateLayoutCell ** hit cache - [0:5] 156\n** FDTemplateLayoutCell ** hit cache - [0:6] 165\n```\n\n## About self-satisfied cell\n\na fully **self-satisfied** cell is constrainted by auto layout and each edge(\"top\", \"left\", \"bottom\", \"right\") has at least one layout constraint against it. It's the same concept introduced as \"self-sizing cell\" in iOS8 using auto layout.\n\nA bad one :( - missing right and bottom\n![non-self-satisfied](https://github.com/forkingdog/UITableView-FDTemplateLayoutCell/blob/master/Sceenshots/screenshot0.png)   \n\nA good one :)  \n![self-satisfied](https://github.com/forkingdog/UITableView-FDTemplateLayoutCell/blob/master/Sceenshots/screenshot1.png)   \n\n## Notes\n\nA template layout cell is created by `-dequeueReusableCellWithIdentifier:` method, it means that you MUST have registered this cell reuse identifier by one of:  \n\n- A prototype cell of UITableView in storyboard.\n- Use `-registerNib:forCellReuseIdentifier:` \n- Use `-registerClass:forCellReuseIdentifier:`\n\n## 如果你在天朝\n可以看这篇中文博客： \n[http://blog.sunnyxx.com/2015/05/17/cell-height-calculation/](http://blog.sunnyxx.com/2015/05/17/cell-height-calculation/)\n\n## Installation\n\nLatest version: **1.6**\n\n```\npod search UITableView+FDTemplateLayoutCell \n```\nIf you cannot search out the latest version, try:  \n\n```\npod setup\n```\n\n## Release Notes\n\nWe recommend to use the latest release in cocoapods.\n\n- 1.6\nfix bug in iOS 10\n\n- 1.4  \nRefactor, add \"cacheByKey\" mode, bug fixed\n\n- 1.3  \nFrame layout mode, handle cell's accessory view/type\n\n- 1.2  \nPrecache and auto cache invalidation\n\n- 1.1  \nHeight cache\n\n- 1.0  \nBasic automatically height calculation\n\n## License\nMIT\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fforkingdog%2FUITableView-FDTemplateLayoutCell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fforkingdog%2FUITableView-FDTemplateLayoutCell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fforkingdog%2FUITableView-FDTemplateLayoutCell/lists"}