UITableView 与 UICollectionView 好像是两个团队开发的似的

  1. 常量不统一,一个用负数,一个用 MAX

    UITableViewAutomaticDimension = -1.000000
    UICollectionViewFlowLayoutAutomaticSize = {1.7976931348623157e+308, 1.7976931348623157e+308}
    
  2. HeaderFooter 类名、Cell 继承链不同

    @interface UITableViewHeaderFooterView : UIView
    @interface UITableViewCell : UIView
    
    @interface UICollectionReusableView : UIView
    @interface UICollectionViewCell : UICollectionReusableView
    

    自定义子类时,要实现的 init 方法也都不同

    // UITableViewHeaderFooterView
    - initWithReuseIdentifier:
    // UITableViewCell
    - initWithStyle: reuseIdentifier:
    
    // UICollectionReusableView
    - initWithFrame:
    // UICollectionViewCell
    - initWithFrame:
    

还有,所有类都有属性 contentView,唯独 UICollectionReusableView 没有

  1. HeaderFooter 的代理方法不同

    - (UIView *)tableView: viewForHeaderInSection:
    - (UIView *)tableView: viewForFooterInSection:
    
    - (UICollectionReusableView *)collectionView: viewForSupplementaryElementOfKind: atIndexPath:
    

    可能我了解得还不够深,如果 CollectionView 可以注册自定义的 UICollectionElementKind..., 那这一点应该还说得的过去

    获取复用 HeaderFooter 的方法名、表现也不同

    // nullable 还得手动判 nil ,手动创建
    - (nullable ...)dequeueReusableHeaderFooterViewWithIdentifier:
    
    // nonnull 类似 Cell,很好用
    - (...)dequeueReusableSupplementaryViewOfKind: withReuseIdentifier: forIndexPath:
    

你可能感兴趣的:(UITableView 与 UICollectionView 好像是两个团队开发的似的)