折叠tableView的实现

这篇日记是自己的笔记,给自己看的,太懒也没有整理。虽然简单还是复制粘贴了一下。
这里是一个折叠的tableView的简单实现,主要思路是:多个Sections,每个Section下多个Rows,SectionHeader可以做为第一层,Sction对应的Rows作为折叠层。实现Rows的展开和收起。

  • 折叠tableView实现
  • SectionHeaderView复用
  • 模型以及数据的处理

代码

Controller.h

#import "WMSTableViewControllerBase.h"

@class WMSBinInventory;@class WMSBinLot;

NS_ASSUME_NONNULL_BEGIN

/// Cell
@interface WMSBinInventoryCell : UITableViewCell

@property (nonatomic, strong) UILabel *expDateLabel;    // PurchaseTrans.ExpirationDate label
@property (nonatomic, strong) UILabel *batchCodeLabel; // PurchaseTrans.BatchCode lable
@property (nonatomic, strong) UILabel *inventoryLabel; // BinLots.Inventory label

@property (nonatomic, strong) WMSBinLot *binLot;

@end


/// Section header
@interface WMSBinInventoryTableSctionView : UITableViewHeaderFooterView

@property (nonatomic, strong) WMSBinInventory *inventory;

@property (nonatomic) NSInteger section;

@property (nonatomic, copy) void(^SectionUpBlackBtnCallBack)(UIButton *sender, NSInteger section);

@end


/// Controller
@interface WMSProductBinInventoryViewController : WMSTableViewControllerBase

- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithProductID:(NSString *)productID
                      productName:(NSString *)productName;

@property (nonatomic, copy, readonly) NSString *productID;
@property (nonatomic, copy, readonly) NSString *productName;

@end


/// Model
@interface WMSBinLot : NSObject

@property (nonatomic, copy) NSString *expirationDate; // PurchaseTrans.ExpirationDate
@property (nonatomic, copy) NSString *batchCode;      // PurchaseTrans.BatchCode
@property (nonatomic, copy) NSString *inventory;      // BinLots.Inventory

@end

@interface WMSBinInventory : NSObject

@property (nonatomic, copy) NSString *bin;             // Bins.Bin
@property (nonatomic, copy) NSString *binZone;         // BinZones.BinZone
@property (nonatomic, copy) NSString *capacity;        // Bins.Capacity
@property (nonatomic, copy) NSString *pickPending;     // BinInventories.PickPending
@property (nonatomic, copy) NSString *inventory;       // BinInventories.Inventory
@property (nonatomic, copy) NSString *displayInventory;// The show num of BinInventories.Inventory.
@property (nonatomic, copy) NSMutableArray <WMSBinLot *> *binLotArray;

@property (nonatomic) BOOL hiddenDownBtn; // Whether to show the down button in section heaser. If do not any binlots data, the button will be hidden.
@property (nonatomic) BOOL showRows;    // Whether to show rows details. Detault is NO.

- (instancetype)initWithAttributes:(NSDictionary *)dict;

@end

NS_ASSUME_NONNULL_END

Controller.m

#import "WMSProductBinInventoryViewController.h"

#define kWMSBinInventoryTableSctionViewIdentifier @"WMSBinInventoryTableSctionViewIdentifier"


@interface WMSBinInventoryCell ()

@property (nonatomic, strong) UIView *leftLine;
@property (nonatomic, strong) UIView *rightLine;
@property (nonatomic, strong) UIView *centerLine;

@end

@implementation WMSBinInventoryCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
                
        self.expDateLabel = [[UILabel alloc] init];
        self.expDateLabel.textColor = [UIColor lightGrayColor];
        self.expDateLabel.font = [UIFont systemFontOfSize:12.0];
        self.expDateLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:self.expDateLabel];
        
        self.batchCodeLabel = [[UILabel alloc] init];
        self.batchCodeLabel.textColor = [UIColor lightGrayColor];
        self.batchCodeLabel.font = [UIFont systemFontOfSize:12.0];
        self.batchCodeLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:self.batchCodeLabel];
        
        self.inventoryLabel = [[UILabel alloc] init];
        self.inventoryLabel.textColor = [UIColor lightGrayColor];
        self.inventoryLabel.font = [UIFont systemFontOfSize:12.0];
        self.inventoryLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:self.inventoryLabel];
        
        self.leftLine = [[UIView alloc] init];
        self.leftLine.backgroundColor = [UIColor lightGrayColor];
        [self insertSubview:self.leftLine aboveSubview:self.expDateLabel];
        
        self.rightLine = [[UIView alloc] init];
        self.rightLine.backgroundColor = [UIColor lightGrayColor];
        [self insertSubview:self.rightLine aboveSubview:self.inventoryLabel];
        
        self.centerLine = [[UIView alloc] init];
        self.centerLine.backgroundColor = [UIColor lightGrayColor];
        [self insertSubview:self.centerLine aboveSubview:self.batchCodeLabel];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.expDateLabel.frame = CGRectMake(16, 0, (CGRectGetWidth(self.frame)-64)/3, CGRectGetHeight(self.frame));
    
    self.batchCodeLabel.frame = CGRectMake(16+CGRectGetMaxX(self.expDateLabel.frame), CGRectGetMinY(self.expDateLabel.frame), CGRectGetWidth(self.expDateLabel.frame), CGRectGetHeight(self.expDateLabel.frame));
    
    self.inventoryLabel.frame = CGRectMake(16+CGRectGetMaxX(self.batchCodeLabel.frame), CGRectGetMinY(self.expDateLabel.frame), CGRectGetWidth(self.expDateLabel.frame), CGRectGetHeight(self.expDateLabel.frame));
    
    self.leftLine.frame = CGRectMake(0, 0, 0.5, CGRectGetHeight(self.frame));
    self.rightLine.frame = CGRectMake(CGRectGetWidth(self.frame), 0, 0.5, CGRectGetHeight(self.frame));
    self.centerLine.frame = CGRectMake(CGRectGetMaxX(self.leftLine.frame), CGRectGetHeight(self.frame)-0.5, CGRectGetWidth(self.frame), 0.5);
}

- (void)setBinLot:(WMSBinLot *)binLot
{
    _binLot = binLot;
    
    self.expDateLabel.text = binLot.expirationDate;
    self.batchCodeLabel.text = binLot.batchCode;
    self.inventoryLabel.text = binLot.inventory;
}

- (void)setFrame:(CGRect)frame
{
    NSInteger insert = 20;
    frame.origin.x += insert;
    frame.size.width -= 2 * insert;
    
    [super setFrame:frame];
}

@end


@interface WMSBinInventoryTableSctionView ()

@property (nonatomic, strong) UIView *titleView;
@property (nonatomic, strong) UILabel *binZoneTitleLabel;
@property (nonatomic, strong) UILabel *capacityTitleLabel;
@property (nonatomic, strong) UILabel *pickPendingTitleLabel;
@property (nonatomic, strong) UILabel *binInventoryTitleLabel;

@property (nonatomic, strong) UIView *detailView;
@property (nonatomic, strong) UIButton *downBtn;
@property (nonatomic, strong) UILabel *binBinZoneLabel;     // Bins.Bin - BinZons.BinZone
@property (nonatomic, strong) UILabel *capacityLabel;       // Bins.Capacity
@property (nonatomic, strong) UILabel *pickPendingLabel;    // BinInventories.PickPending
@property (nonatomic, strong) UILabel *inventoryLabel;      // BinInventories.Inventory


@property (nonatomic, strong) UIView *rowsTitleView;
@property (nonatomic, strong) UILabel *dateTitleLabel;
@property (nonatomic, strong) UILabel *batchCodeTitleLabel;
@property (nonatomic, strong) UILabel *inventoryTitleLabel;

@end

@implementation WMSBinInventoryTableSctionView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier])
    {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        
        self.titleView = [[UIView alloc] init];
        self.titleView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.3];
        [self addSubview:self.titleView];
        
        self.binZoneTitleLabel = [[UILabel alloc] init];
        self.binZoneTitleLabel.text = @"Bin Zone";
        self.binZoneTitleLabel.font = [UIFont systemFontOfSize:15.0];
        self.binZoneTitleLabel.textColor = [UIColor blackColor];
        [self.titleView addSubview:self.binZoneTitleLabel];
        
        self.capacityTitleLabel = [[UILabel alloc] init];
        self.capacityTitleLabel.text = @"Capacity";
        self.capacityTitleLabel.font = [UIFont systemFontOfSize:15.0];
        self.capacityTitleLabel.textColor = [UIColor blackColor];
        [self.titleView addSubview:self.capacityTitleLabel];
        
        self.pickPendingTitleLabel = [[UILabel alloc] init];
        self.pickPendingTitleLabel.text = @"Pick Pending";
        self.pickPendingTitleLabel.font = [UIFont systemFontOfSize:15.0];
        self.pickPendingTitleLabel.textColor = [UIColor blackColor];
        [self.titleView addSubview:self.pickPendingTitleLabel];
        
        self.binInventoryTitleLabel = [[UILabel alloc] init];
        self.binInventoryTitleLabel.text = @"Inventory";
        self.binInventoryTitleLabel.font = [UIFont systemFontOfSize:15.0];
        self.binInventoryTitleLabel.textColor = [UIColor blackColor];
        [self.titleView addSubview:self.binInventoryTitleLabel];

        
        
        
        self.detailView = [[UIView alloc] init];
        self.detailView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.1];
        [self addSubview:self.detailView];
                
        self.downBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.downBtn setImage:[UIImage imageNamed:@"PlusIcon_Down"] forState:UIControlStateNormal];
        [self.downBtn setImage:[UIImage imageNamed:@"MinusIcon_Up"] forState:UIControlStateSelected];
        [self.downBtn addTarget:self action:@selector(downBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        self.downBtn.hidden = YES;
        [self.detailView addSubview:self.downBtn];
        
        self.binBinZoneLabel = [[UILabel alloc] init];
        self.binBinZoneLabel.textColor = [UIColor blackColor];
        self.binBinZoneLabel.font = [UIFont systemFontOfSize:14.0];
        [self.detailView addSubview:self.binBinZoneLabel];
        
        self.capacityLabel = [[UILabel alloc] init];
        self.capacityLabel.textColor = [UIColor blackColor];
        self.capacityLabel.font = [UIFont systemFontOfSize:14.0];
        [self.detailView addSubview:self.capacityLabel];
        
        self.pickPendingLabel = [[UILabel alloc] init];
        self.pickPendingLabel.textColor = [UIColor blackColor];
        self.pickPendingLabel.font = [UIFont systemFontOfSize:14.0];
        [self.detailView addSubview:self.pickPendingLabel];
        
        self.inventoryLabel = [[UILabel alloc] init];
        self.inventoryLabel.textColor = [UIColor blackColor];
        self.inventoryLabel.font = [UIFont systemFontOfSize:14.0];
        [self.detailView addSubview:self.inventoryLabel];
        
        
        
        self.rowsTitleView = [[UIView alloc] init];
        self.rowsTitleView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.4];
        self.rowsTitleView.layer.borderColor = [UIColor lightGrayColor].CGColor;
        self.rowsTitleView.layer.borderWidth = 0.5;
        [self insertSubview:self.rowsTitleView aboveSubview:self.detailView];
        
        self.dateTitleLabel = [[UILabel alloc] init];
        self.dateTitleLabel.textColor = [UIColor blackColor];
        self.dateTitleLabel.font = [UIFont systemFontOfSize:13.0];
        self.dateTitleLabel.text = @"  Date";
        [self.rowsTitleView addSubview:self.dateTitleLabel];
        
        self.batchCodeTitleLabel = [[UILabel alloc] init];
        self.batchCodeTitleLabel.textColor = [UIColor blackColor];
        self.batchCodeTitleLabel.font = [UIFont systemFontOfSize:13.0];
        self.batchCodeTitleLabel.text = @"Batch";
        [self.rowsTitleView addSubview:self.batchCodeTitleLabel];

        self.inventoryTitleLabel = [[UILabel alloc] init];
        self.inventoryTitleLabel.textColor = [UIColor blackColor];
        self.inventoryTitleLabel.font = [UIFont systemFontOfSize:13.0];
        self.inventoryTitleLabel.text = @"Inventory";
        [self.rowsTitleView addSubview:self.inventoryTitleLabel];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.titleView.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), 40);
    
    self.binZoneTitleLabel.frame = CGRectMake(16, 0, (CGRectGetWidth(self.frame)-32)/4, CGRectGetHeight(self.titleView.frame));
    self.capacityTitleLabel.frame = CGRectMake(CGRectGetMaxX(self.binZoneTitleLabel.frame), CGRectGetMinY(self.binZoneTitleLabel.frame), CGRectGetWidth(self.binZoneTitleLabel.frame), CGRectGetHeight(self.binZoneTitleLabel.frame));
    self.pickPendingTitleLabel.frame = CGRectMake(CGRectGetMaxX(self.capacityTitleLabel.frame), CGRectGetMinY(self.binZoneTitleLabel.frame), CGRectGetWidth(self.binZoneTitleLabel.frame), CGRectGetHeight(self.binZoneTitleLabel.frame));
    self.binInventoryTitleLabel.frame = CGRectMake(CGRectGetMaxX(self.pickPendingTitleLabel.frame), CGRectGetMinY(self.binZoneTitleLabel.frame), CGRectGetWidth(self.binZoneTitleLabel.frame), CGRectGetHeight(self.binZoneTitleLabel.frame));
    
    self.detailView.frame = CGRectMake(0, CGRectGetMaxY(self.titleView.frame), CGRectGetWidth(self.frame), 60);
    self.downBtn.frame = CGRectMake(16, CGRectGetHeight(self.detailView.frame)*0.5-10, 20, 20);
    self.binBinZoneLabel.frame = CGRectMake(CGRectGetMaxX(self.downBtn.frame) + 8, 0, (CGRectGetWidth(self.frame)-52)/4, CGRectGetHeight(self.detailView.frame));
    self.capacityLabel.frame = CGRectMake(CGRectGetMaxX(self.binBinZoneLabel.frame), CGRectGetMinY(self.binBinZoneLabel.frame), CGRectGetWidth(self.binBinZoneLabel.frame), CGRectGetHeight(self.binBinZoneLabel.frame));
    self.pickPendingLabel.frame = CGRectMake(CGRectGetMaxX(self.capacityLabel.frame), CGRectGetMinY(self.binBinZoneLabel.frame), CGRectGetWidth(self.capacityLabel.frame), CGRectGetHeight(self.binBinZoneLabel.frame));
    self.inventoryLabel.frame = CGRectMake(CGRectGetMaxX(self.pickPendingLabel.frame), CGRectGetMinY(self.binBinZoneLabel.frame), CGRectGetWidth(self.capacityLabel.frame), CGRectGetHeight(self.binBinZoneLabel.frame));
    
    
    self.rowsTitleView.frame = CGRectMake(20, CGRectGetMaxY(self.detailView.frame) + 10, CGRectGetWidth(self.frame)-40, 40);
    self.dateTitleLabel.frame = CGRectMake(0, 0, CGRectGetWidth(self.rowsTitleView.frame)/3, 40);
    self.batchCodeTitleLabel.frame = CGRectMake(CGRectGetMaxX(self.dateTitleLabel.frame), 0, CGRectGetWidth(self.dateTitleLabel.frame), CGRectGetHeight(self.dateTitleLabel.frame));
    self.inventoryTitleLabel.frame = CGRectMake(CGRectGetMaxX(self.batchCodeTitleLabel.frame), 0, CGRectGetWidth(self.dateTitleLabel.frame), CGRectGetHeight(self.dateTitleLabel.frame));
}

- (void)setInventory:(WMSBinInventory *)inventory
{
    _inventory = inventory;
    
    self.binBinZoneLabel.text = [NSString stringWithFormat:@"%@ - %@",inventory.bin,inventory.binZone];
    self.binBinZoneLabel.numberOfLines = 2;
    
    self.capacityLabel.text = inventory.capacity;
    self.pickPendingLabel.text = inventory.pickPending;
    
    self.inventoryLabel.text = inventory.displayInventory;
    
    self.downBtn.hidden = inventory.hiddenDownBtn;
    self.downBtn.selected = inventory.showRows;
    self.rowsTitleView.hidden = !inventory.showRows;
}

- (void)setSection:(NSInteger)section
{
    _section = section;
}

- (void)downBtnAction:(UIButton *)sender
{
    if (self.SectionUpBlackBtnCallBack) {
        self.SectionUpBlackBtnCallBack(sender, self.section);
    }
}

@end


@interface WMSProductBinInventoryViewController ()

@property (nonatomic, copy, readwrite) NSString *productID;
@property (nonatomic, copy, readwrite) NSString *productName;

@property (nonatomic, strong) NSMutableArray <WMSBinInventory *> *dataSource;

@end

@implementation WMSProductBinInventoryViewController

- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [[NSMutableArray alloc] init];
    }
    return _dataSource;
}

- (instancetype)initWithProductID:(NSString *)productID productName:(NSString *)productName {
    if (self = [super init]) {
        self.productID = productID;
        self.productName = productName;
        self.title = self.productName;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initViews];
    
    [self requestBinLotsData];
}

- (void)initViews {
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.sectionFooterHeight = 20;
    [self.tableView registerClass:[WMSBinInventoryTableSctionView class] forHeaderFooterViewReuseIdentifier:kWMSBinInventoryTableSctionViewIdentifier];
}

- (void)requestBinLotsData
{
	// ...

    // Debug data
    for (int i = 0; i < 10; i++)
    {
        NSArray *binLot = @[
        @{@"ExpirationDate":@"2020.10.28",
                                 @"BatchCode":@"",
                                 @"BinLotInventory":@"1"
        },
        @{@"ExpirationDate":@"2020.10.29",
                                 @"BatchCode":@"",
                                 @"BinLotInventory":@"9"
        }];
        NSDictionary *dict = @{@"Bin":@"jc",
                               @"BinZone":@"C3",
                               @"Capacity":@"102",
                               @"PickPending":@"15",
                               @"BinInventory":@"10.000",
                               @"DisplayInventory":@"10",
                               @"BinLots":binLot,
        };
        WMSBinInventory *inventory = [[WMSBinInventory alloc] initWithAttributes:dict];
        [self.dataSource addObject:inventory];
    }
    [self.tableView reloadData];
}

#pragma mark - Request

- (void)requestFinished:(ASIHTTPRequest *)request{
    
    [self hideProgressView];
    
    NSString *responseString = [request responseString];

    if (request.tag == WMSHttpRequestTypeVPGetBinInventories)
    {
        NSData *jsonData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
        NSError *err;
        NSDictionary *response = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
        NSDictionary *data = response[@"data"];
        if (err == nil && data.count > 0)
        {
            for (NSDictionary *dict in data)
            {
                WMSBinInventory *inventory = [[WMSBinInventory alloc] initWithAttributes:dict];
                [self.dataSource addObject:inventory];
            }
            [self.tableView reloadData];
        }
        else {

        }
    }
}

- (void)requestFailed:(ASIHTTPRequest *)request {
    
    [self hideProgressView];
    
    [self showAlertViewOfRequestFailed];
}

#pragma mark - TableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataSource.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    WMSBinInventory *inventory = self.dataSource[section];
    return (inventory.showRows) ? inventory.binLotArray.count : 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"WMSProductBinInventoryViewController_UITableViewCell";
    WMSBinInventoryCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[WMSBinInventoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    WMSBinInventory *inventory = self.dataSource[indexPath.section];
    WMSBinLot *binLot = inventory.binLotArray[indexPath.row];
    cell.binLot = binLot;
    return cell;
}
- (CGFloat)tableView:( UITableView *)tableView heightForHeaderInSection:( NSInteger )section
{
    WMSBinInventory *inventory = self.dataSource[section];
    if (inventory.showRows) {
        return 40 + 60 + 50;
    }
    return 40 + 60; // Section titles height + Detail num height.
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    WMSBinInventoryTableSctionView *sectionView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kWMSBinInventoryTableSctionViewIdentifier];
    if (sectionView == nil) {
        sectionView = [[WMSBinInventoryTableSctionView alloc] initWithReuseIdentifier:kWMSBinInventoryTableSctionViewIdentifier];
    }
    [sectionView setSection:section];
    [sectionView setInventory:self.dataSource[section]];
    
    __weak typeof(self)weakSelf = self;
    sectionView.SectionUpBlackBtnCallBack = ^(UIButton * _Nonnull sender, NSInteger section) {
                
        WMSBinInventory *inventory = self.dataSource[section];
        inventory.showRows = !inventory.showRows;
        
        [weakSelf.tableView reloadSections:[[NSIndexSet alloc]initWithIndex:section] withRowAnimation:UITableViewRowAnimationAutomatic];
    };
    
    return sectionView;
}

@end


@implementation WMSBinLot

- (instancetype)initWithBinLotInfo:(NSDictionary *)dict
{
    if (self = [super init])
    {
        self.expirationDate = [WMSFmt safeString:dict[@"ExpirationDate"]];
        self.batchCode = [WMSFmt safeString:dict[@"BatchCode"]];
        self.inventory = [WMSFmt numberStringFormat:[WMSFmt safeString:dict[@"BinLotInventory"]]];
    }
    return self;
}

@end


@implementation WMSBinInventory

- (instancetype)initWithAttributes:(NSDictionary *)dict
{
    if (self = [super init])
    {
        self.bin = [WMSFmt safeString:dict[@"Bin"]];
        self.binZone = [WMSFmt safeString:dict[@"BinZone"]];
        self.capacity = [WMSFmt numberStringFormat:[WMSFmt safeString:dict[@"Capacity"]]];
        self.pickPending = [WMSFmt numberStringFormat:[WMSFmt safeString:dict[@"PickPending"]]];
        self.displayInventory = [WMSFmt numberStringFormat:[WMSFmt safeString:dict[@"DisplayInventory"]]];
        self.inventory = dict[@"BinInventory"];
        
        [self.binLotArray removeAllObjects];
        
        for (NSDictionary *info in dict[@"BinLots"])
        {
            WMSBinLot *binLot = [[WMSBinLot alloc] initWithBinLotInfo:info];
            [self.binLotArray addObject:binLot];
        }
        self.hiddenDownBtn = (self.binLotArray.count > 0) ? NO : YES;
    }
    return self;
}

- (NSMutableArray<WMSBinLot *> *)binLotArray {
    if (!_binLotArray) {
        _binLotArray = [[NSMutableArray alloc] init];
    }
    return _binLotArray;
}

@end

主要点

  • 自定义SectionHeaderView

  • SectionHeader复用

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    WMSBinInventoryTableSctionView *sectionView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kWMSBinInventoryTableSctionViewIdentifier];
    if (sectionView == nil) {
        sectionView = [[WMSBinInventoryTableSctionView alloc] initWithReuseIdentifier:kWMSBinInventoryTableSctionViewIdentifier];
    }
    // ...    
    return sectionView;
}
[self.tableView registerClass:[WMSBinInventoryTableSctionView class] forHeaderFooterViewReuseIdentifier:kWMSBinInventoryTableSctionViewIdentifier];
  • 刷新某个Secion
[self.tableView reloadSections:[[NSIndexSet alloc]initWithIndex:section] withRowAnimation:UITableViewRowAnimationAutomatic];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Morris_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值