UITableView(FWDynamicLayout)

@interface UITableView (FWDynamicLayout)

表格自动计算并缓存cell高度分类,最底部view的MaxY即为cell高度,自定义方案实现

如果使用系统自动高度,建议设置estimatedRowHeight提高性能

Cache

  • 手工清空所有高度缓存,用于高度发生变化的情况

    Declaration

    Objective-C

    - (void)fw_clearHeightCache;
  • 指定indexPath设置cell高度缓存,如willDisplayCell调用,height为cell.frame.size.height,设置为0时清除缓存

    Declaration

    Objective-C

    - (void)fw_setCellHeightCache:(CGFloat)height
                     forIndexPath:(nonnull NSIndexPath *)indexPath;
  • 指定key设置cell高度缓存,如willDisplayCell调用,height为cell.frame.size.height,设置为0时清除缓存

    Declaration

    Objective-C

    - (void)fw_setCellHeightCache:(CGFloat)height forKey:(nonnull id<NSCopying>)key;
  • 指定indexPath获取cell缓存高度,如estimatedHeightForRow调用,默认值automaticDimension

    Declaration

    Objective-C

    - (CGFloat)fw_cellHeightCacheForIndexPath:(nonnull NSIndexPath *)indexPath;
  • 指定key获取cell缓存高度,如estimatedHeightForRow调用,默认值automaticDimension

    Declaration

    Objective-C

    - (CGFloat)fw_cellHeightCacheForKey:(nonnull id<NSCopying>)key;
  • 指定section设置HeaderFooter高度缓存,如willDisplayHeaderFooter调用,height为view.frame.size.height,设置为0时清除缓存

    Declaration

    Objective-C

    - (void)fw_setHeaderFooterHeightCache:(CGFloat)height
                                     type:(FWHeaderFooterViewType)type
                               forSection:(NSInteger)section;
  • 指定key设置HeaderFooter高度缓存,如willDisplayHeaderFooter调用,height为view.frame.size.height,设置为0时清除缓存

    Declaration

    Objective-C

    - (void)fw_setHeaderFooterHeightCache:(CGFloat)height
                                     type:(FWHeaderFooterViewType)type
                                   forKey:(nonnull id<NSCopying>)key;
  • 指定section获取HeaderFooter缓存高度,如estimatedHeightForHeaderFooter调用,默认值automaticDimension

    Declaration

    Objective-C

    - (CGFloat)fw_headerFooterHeightCache:(FWHeaderFooterViewType)type
                               forSection:(NSInteger)section;
  • 指定key获取HeaderFooter缓存高度,如estimatedHeightForHeaderFooter调用,默认值automaticDimension

    Declaration

    Objective-C

    - (CGFloat)fw_headerFooterHeightCache:(FWHeaderFooterViewType)type
                                   forKey:(nonnull id<NSCopying>)key;

Cell

  • 获取 Cell 需要的高度,内部无缓存操作

    Declaration

    Objective-C

    - (CGFloat)fw_heightWithCellClass:(nonnull Class)clazz
                        configuration:
                            (nonnull FWCellConfigurationBlock)configuration;

    Parameters

    clazz

    cell类

    configuration

    布局cell句柄,内部不会拥有Block,不需要__weak

    Return Value

    cell高度

  • 获取 Cell 需要的高度,内部自动处理缓存,缓存标识 indexPath

    Declaration

    Objective-C

    - (CGFloat)fw_heightWithCellClass:(nonnull Class)clazz
                     cacheByIndexPath:(nonnull NSIndexPath *)indexPath
                        configuration:
                            (nonnull FWCellConfigurationBlock)configuration;

    Parameters

    clazz

    cell class

    indexPath

    使用 indexPath 做缓存标识

    configuration

    布局 cell,内部不会拥有 Block,不需要 __weak

  • 获取 Cell 需要的高度,内部自动处理缓存,缓存标识 key

    Declaration

    Objective-C

    - (CGFloat)fw_heightWithCellClass:(nonnull Class)clazz
                           cacheByKey:(nullable id<NSCopying>)key
                        configuration:
                            (nonnull FWCellConfigurationBlock)configuration;

    Parameters

    clazz

    cell class

    key

    使用 key 做缓存标识,如数据唯一id,对象hash等

    configuration

    布局 cell,内部不会拥有 Block,不需要 __weak

HeaderFooterView

UITableView+FWUIKit

  • 全局清空TableView默认多余边距

    Declaration

    Objective-C

    + (void)fw_resetTableStyle;
  • 是否启动高度估算布局,启用后需要子视图布局完整,无需实现heightForRow方法(iOS11默认启用,会先cellForRow再heightForRow)

    Declaration

    Objective-C

    @property (nonatomic) BOOL fw_estimatedLayout;
  • 清除Grouped等样式默认多余边距,注意CGFLOAT_MIN才会生效,0不会生效

    Declaration

    Objective-C

    - (void)fw_resetTableStyle;
  • reloadData完成回调

    Declaration

    Objective-C

    - (void)fw_reloadDataWithCompletion:(nullable void (^)(void))completion;
  • reloadData禁用动画

    Declaration

    Objective-C

    - (void)fw_reloadDataWithoutAnimation;