文档章节

UITableView-FDTemplateLayoutCell

ming_sr
 ming_sr
发布于 2016/11/10 00:55
字数 484
阅读 130
收藏 0

「深度学习福利」大神带你进阶工程师,立即查看>>>

 

 

 

 

Overview

Template auto layout cell for automatically UITableViewCell height calculating.

 

 

 

Basic usage

If you have a self-satisfied cell, then all you have to do is:

#import UITableView+FDTemplateLayoutCell.h

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [tableView fd_heightForCellWithIdentifier:reuse identifer configuration:^( cell) {
        // Configure this cell with data, same as what you've done in "-tableView:cellForRowAtIndexPath:"
        // Like:
        //    cell.entity = self.feedEntities[indexPath.row];
    }];
}

Height Caching API

Since 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:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [tableView fd_heightForCellWithIdentifier:identifer cacheByIndexPath:indexPath configuration:^( cell) {
        // configurations
    }];
}

Or, if your entity has an unique identifier, use cache by key API:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    Entity *entity = self.entities[indexPath.row];
    return [tableView fd_heightForCellWithIdentifier:identifer cacheByKey:entity.uid configuration:^( cell) {
        // configurations
    }];
}

Frame layout mode

FDTemplateLayoutCell offers 2 modes for asking cell's height.

  1. Auto layout mode using "-systemLayoutSizeFittingSize:"
  2. Frame layout mode using "-sizeThatFits:"

Generally, 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:

cell.fd_enforceFrameLayout = ;

And if you're using frame layout mode, you must override -sizeThatFits: in your customized cell and return content view's height (separator excluded)

- (CGSize)sizeThatFits:(CGSize)size {
    return CGSizeMake(size.width, A+B+C+D+E+....);
}

Debug log

Debug 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".

self.tableView.fd_debugLogEnabled = ;

It will print like this:

** FDTemplateLayoutCell ** layout cell created - FDFeedCell
** FDTemplateLayoutCell ** calculate - [:] 233.5
** FDTemplateLayoutCell ** calculate - [:] 155.5
** FDTemplateLayoutCell ** calculate - [:] 
** FDTemplateLayoutCell ** calculate - [:] 
** FDTemplateLayoutCell ** precached - [:] 
** FDTemplateLayoutCell ** calculate - [:] 278.5
** FDTemplateLayoutCell ** precached - [:] 278.5
** FDTemplateLayoutCell ** hit cache - [:] 
** FDTemplateLayoutCell ** hit cache - [:] 278.5
** FDTemplateLayoutCell ** hit cache - [:] 
** FDTemplateLayoutCell ** hit cache - [:]

About self-satisfied cell

a 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.

A bad one :( - missing right and bottom

 

 

A good one :)

 

 

Notes

A template layout cell is created by -dequeueReusableCellWithIdentifier: method, it means that you MUST have registered this cell reuse identifier by one of:

  • A prototype cell of UITableView in storyboard.
  • Use -registerNib:forCellReuseIdentifier:
  • Use -registerClass:forCellReuseIdentifier:

如果你在天朝

可以看这篇中文博客: http://blog.sunnyxx.com/2015/05/17/cell-height-calculation/

Installation

Latest version: 1.4.beta

pod search UITableView+FDTemplateLayoutCell 

If you cannot search out the latest version, try:

pod setup

Release Notes

We recommend to use the latest release in cocoapods.

  • 1.4
    Refactor, add "cacheByKey" mode, bug fixed

  • 1.3
    Frame layout mode, handle cell's accessory view/type

  • 1.2
    Precache and auto cache invalidation

  • 1.1
    Height cache

  • 1.0
    Basic automatically height calculation

License

ming_sr
粉丝 0
博文 2
码字总数 0
作品 0
广州
程序员
私信 提问
加载中
请先登录后再评论。
首列固定的列表

实现特殊的表格(UITableView)效果:即表格中的首列固定不动,而每一行除了首列均可左右拖动,以展现每一行更多内容。 作者谭林江(@无法越狱的痛)说:去益盟面试回来,感觉聊得有点郁闷,...

匿名
2013/01/24
1.3K
0
StaticDataTableViewController

StaticDataTableViewController 可以使用动画效果显示和隐藏 UITableView 的静态单元 (created in IB, using the option Content : Static cells)...

匿名
2013/03/08
387
0
HHPanningTableViewCell

HHPanningTableViewCell是一个UITableViewCell实现“刷卡显示”抽屉视图。这种观点通常包含应用到当前行的操作按钮。此行为被看作在数量iOS应用程序。据我所知,当时的想法是首创的罗兰Brich...

匿名
2012/10/24
441
0
UIListView

自定义列表,可设置列表的滑动方向为横向或者纵向,滑动方式可自定义为:分块滑动、分页滑动,外加自动滑动。 作者注:代码缺少注释,多多见谅。其中有许多不足之处,尤其是内存方面,谁知道...

匿名
2012/11/18
1.4K
0
Sliding Grid View

SlidingGridView 是一个表格组件,支持滑动动画效果:更新单元格从上到小替换老的内容。 特点: 1. Unique sliding animation. 2. Shake to refresh. 3. Mimics "load more..." items. 4. Ab......

匿名
2012/12/24
659
0

没有更多内容

加载失败,请刷新页面

加载更多

您如何加速Eclipse? - How can you speed up Eclipse?

问题: How can you make the experience with Eclipse faster? 如何使Eclipse体验更快? For instance: I disable all the plugins I don't need (Mylyn, Subclipse, …). 例如: 我禁用了所......

fyin1314
19分钟前
9
0
百度地图SDK新版内测邀请

本文作者:用****9 百度地图开放平台为开发者提供七大基础服务能力,其中地图SDK和导航SDK是开发者广泛使用的重要基础服务,为了满足开发者更多使用需求以及提升开发者集成后的应用效果,本次...

百度开发者中心
前天
27
0
获取JavaScript数组中的所有唯一值(删除重复项) - Get all unique values in a JavaScript array (remove duplicates)

问题: I have an array of numbers that I need to make sure are unique. 我需要确定一个唯一的数字数组。 I found the code snippet below on the internet and it works great until th......

javail
今天
11
0
如何检查字符串是否为空? - How to check if the string is empty?

问题: Does Python have something like an empty string variable where you can do: Python是否有类似空字符串变量的内容可以在其中执行: if myString == string.empty: Regardless, wh......

富含淀粉
今天
19
0
您如何存储未跟踪的文件? - How do you stash an untracked file?

问题: I have changes to a file, plus a new file, and would like to use git stash to put them away while I switch to another task. 我对一个文件进行了更改,再加上一个新文件,并希......

技术盛宴
今天
39
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部