EMoney 学习

iOS TableView 分区/枚举动态化

2017-09-14  本文已影响0人  大良造L

section动态化

typedef NS_ENUM(NSUInteger, EnumDynamicSection) {
    EnumDynamicSection_1 = 0,
    EnumDynamicSection_2,   // 未知区域数量
    EnumDynamicSection_3,
    EnumDynamicSection_4,   // 未知区域数量
    EnumDynamicSection_5,
    EnumDynamicSection_6,   // 未知区域数量
};
// 配置动态分区信息
- (NSMutableArray <LYTableViewDynamicSectionInfo*>*)optionsOfDynamicSectionInTableView
{
    NSMutableArray *arrayEnum = [NSMutableArray array];
    // 动态分区 区域一
    LYTableViewDynamicSectionInfo *enumInfo1 = [[LYTableViewDynamicSectionInfo alloc] init];
    enumInfo1.indexOfEnum = EnumDynamicSection_2;
    enumInfo1.length = self.arrayDynamicSectionDataOne.count;
    [arrayEnum addObject:enumInfo1];
    // 动态分区 区域二
    LYTableViewDynamicSectionInfo *enumInfo2 = [[LYTableViewDynamicSectionInfo alloc] init];
    enumInfo2.indexOfEnum = EnumDynamicSection_4;
    enumInfo2.length = self.arrayDynamicSectionDataTwo.count;
    [arrayEnum addObject:enumInfo2];
    // 动态分区 区域三
    LYTableViewDynamicSectionInfo *enumInfo3 = [[LYTableViewDynamicSectionInfo alloc] init];
    enumInfo3.indexOfEnum = EnumDynamicSection_6;
    enumInfo3.length = self.arrayDynamicSectionDataThree.count;
    [arrayEnum addObject:enumInfo3];
    
    return arrayEnum;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath dynamicPath:(LYTableViewDynamicPath *)dynamicPath{
    UITableViewCell *cell = [UITableViewCell new];
    switch (dynamicPath.enumIndex) {
        case EnumDynamicSection_1:
        {
            cell.textLabel.text = @"固定分区";
        }
            break;
        case EnumDynamicSection_2:
        {
            cell.textLabel.text = [NSString stringWithFormat:@"动态分区一 - %ld",dynamicPath.index];
        }
            break;
        case EnumDynamicSection_3:
        {
            cell.textLabel.text = @"固定分区";
        }
            break;
        case EnumDynamicSection_4:
        {
            cell.textLabel.text = [NSString stringWithFormat:@"动态分区二 - %ld",dynamicPath.index];
        }
            break;
        case EnumDynamicSection_5:
        {
            cell.textLabel.text = @"固定分区";
        }
            break;
        case EnumDynamicSection_6:
        {
            cell.textLabel.text = [NSString stringWithFormat:@"动态分区三 - %ld",dynamicPath.index];
        }
            break;
        default:
            break;
    }
    return cell;
}
@interface LYTableViewDynamicPath : NSObject
@property (nonatomic, assign) NSInteger enumIndex;      // 动态分区所在枚举
@property (nonatomic, assign) NSInteger index;          // 分区在该动态区域的第几个

@end

github地址: https://github.com/LYKit/LYDynamicSection

上一篇 下一篇

猜你喜欢

热点阅读