IBTTableViewSectionInfo.m 3.35 KB
Newer Older
mei's avatar
mei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
//
//  IBTTableViewSectionInfo.m
//  IBTTableViewKit
//
//  Created by Xummer on 15/1/5.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "IBTTableViewSectionInfo.h"

NSString * const SInfoHeaderKey             = @"header";
NSString * const SInfoFooterKey             = @"footer";
NSString * const SInfoHeaderTitleKey        = @"headerTitle";
NSString * const SInfoFooterTitleKey        = @"footerTitle";

#import "IBTTableViewCellInfo.h"

@interface IBTTableViewSectionInfo ()
{
    NSMutableArray *_arrCells;
}

@end

@implementation IBTTableViewSectionInfo
#pragma mark - Life Cycle
- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

- (void)dealloc {
    _arrCells = nil;
}

#pragma mark - Class Method
+ (id)sectionInfoDefaut {
    return [[IBTTableViewSectionInfo alloc] init];
}

+ (id)sectionInfoHeader:(NSString *)header {
    IBTTableViewSectionInfo *sInfo =  [[self class] sectionInfoDefaut];
    [sInfo setHeaderTitle:header];
    return sInfo;
}

+ (id)sectionInfoFooter:(NSString *)footer {
    IBTTableViewSectionInfo *sInfo =  [[self class] sectionInfoDefaut];
    [sInfo setFooterTitle:footer];
    return sInfo;
}

+ (id)sectionInfoHeader:(NSString *)header Footer:(NSString *)footer {
    IBTTableViewSectionInfo *sInfo =  [[self class] sectionInfoDefaut];
    [sInfo setHeaderTitle:header];
    [sInfo setFooterTitle:footer];
    return sInfo;
}

+ (id)sectionInfoHeaderMakeSel:(SEL)sel makeTarget:(id)target {
    IBTTableViewSectionInfo *sInfo =  [[self class] sectionInfoDefaut];
    sInfo.makeHeaderTarget = target;
    sInfo.makeHeaderSel = sel;
    return sInfo;
}
+ (id)sectionInfoHeaderWithView:(UIView *)view {
    IBTTableViewSectionInfo *sInfo =  [[self class] sectionInfoDefaut];
    [sInfo setHeaderView:view];
    return sInfo;
}

+ (id)sectionInfoFooterWithView:(UIView *)view {
    IBTTableViewSectionInfo *sInfo =  [[self class] sectionInfoDefaut];
    [sInfo setFooterView:view];
    return sInfo;
}

#pragma mark - Public Method

- (NSUInteger)getCellCount {
    return [_arrCells count];
}

- (IBTTableViewCellInfo *)getCellAt:(NSUInteger)index {
    if (index < [self getCellCount]) {
        return _arrCells[ index ];
    }
    
    return nil;
}

- (void)addCell:(IBTTableViewCellInfo *)cell {
    if (![cell isKindOfClass:[IBTTableViewCellInfo class]]) {
        return;
    }
    
    if (!_arrCells) {
        _arrCells = [NSMutableArray array];
    }
    
    [_arrCells addObject:cell];
}

- (void)removeCellAt:(NSUInteger)index {
    if (index < [self getCellCount]) {
        [_arrCells removeObjectAtIndex:index];
    }
}

- (void)setHeaderTitle:(NSString *)title {
    if (title) {
        [self addUserInfoValue:title forKey:SInfoHeaderTitleKey];
        self.fHeaderHeight = -1;
    }
}

- (void)setFooterTitle:(NSString *)title {
    if (title) {
        [self addUserInfoValue:title forKey:SInfoFooterTitleKey];
        self.fFooterHeight = -1;
    }
}

- (UIView *)getHeaderView {
    return [self getUserInfoValueForKey:SInfoHeaderKey];
}

- (void)setHeaderView:(UIView *)view {
    if (view) {
        [self addUserInfoValue:view forKey:SInfoHeaderKey];
        self.fHeaderHeight = CGRectGetHeight(view.frame);
    }
}

- (void)setFooterView:(UIView *)view {
    if (view) {
        [self addUserInfoValue:view forKey:SInfoFooterKey];
        self.fFooterHeight = CGRectGetHeight(view.frame);
    }
}

@end