Latest 0.1.9
Homepage https://github.com/jgyhc/LCFastBuildListKit
License MIT
Platforms ios 8.0
Dependencies UITableView+FDTemplateLayoutCell
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

LCFastBuildListKit is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'LCFastBuildListKit'

Author

jgyhc, [email protected]

License

LCFastBuildListKit is available under the MIT license. See the LICENSE file for more info.

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

LCFastBuildListKit is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'LCFastBuildListKit'

Author

jgyhc, [email protected]

License

LCFastBuildListKit is available under the MIT license. See the LICENSE file for more info.

这个库是干嘛的?(大佬请绕行)

我们在平时的开发中是否有遇到过这样的界面需求,当前界面元素非常多,种类多,常见的视图处理方案便是使用UITableView或者UICollectionView去实现,于是我们就在我们本身就臃肿的ViewController里开始写UITableViewdelegatedataSource方法了,然后我们就可能会看到tableView:cellForRowAtIndexPath:方法里的代码如下:


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger section = indexPath.section;
    if (section == 0) {
        if (indexPath.row == 0) {
            OrderHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderHeaderCell"];
            cell.status = self.data.State;
            return cell;
        } else {
            FBGroupPurchaseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FBGroupPurchaseCell"];
            cell.list = self.productList;
            return cell;
        }
    } else if (section == 2) {

        NSArray *arr = self.resultArr[0];
        if (arr.count == 0) {
            VouchersWaitPayCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VouchersWaitPayCell"];
            return cell;
        } else {
            OrderInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderInfoCell"];
            cell.model = arr[indexPath.row];
            return cell;
        }
    } else if (section == 1) {
        OrderInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderInfoCell"];
        return cell;
    } else {
        OrderInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderInfoCell"];
        NSArray *arr = self.resultArr[section - 2];
        cell.model = arr[indexPath.row];
        if (section == 3 && indexPath.row == arr.count - 1) {
            [cell addline];
        }
        return cell;
    }

}

然后tableView:heightForRowAtIndexPath:方法下可能就是


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger section = indexPath.section;
    if (section == 0) {
        if (indexPath.row == 0) {
            return 60;
        } else {
            return 105;
        }
    } else if (section == 1) {
        return 0;
    } else if (section == 2){
        NSArray *arr = self.resultArr[0];
        if (arr.count > 0) {
            return 30;
        } else {
            return 110;
        }
    } else {
        return 30;
    }
}

对于业务改动不大的场景来说无可厚非,一旦需要在页面中新增一个Cell的时候,缺点一下就出来了,这个时候发现需要改的的地方好像略多了,需要去更改tableView:numberOfRowsInSectio:ntableView:cellForRowAtIndexPath:等方法,而且原来对应的indexPath全都不适用了。

然后呢我就思考了一下,有没有比较好的方式来控制这种方式,让我在以后的维护的时候,少做这样的修改呢?

于是乎,我做过往tableView的数据源里装identifier来区分cell,这样我不再去考虑因为Cell顺序改变带来的会很大程度影响我之前写的代码。但是后来发现还是不够,我们还是需要在tableView:cellForRowAtIndexPath:或者tableView:heightForRowAtIndexPath:写大量的判断逻辑。

为了解决上面的尴尬,我就想封装了一下UITableViewUICollectionView的代理方法,统一了对TableViewCellCollectionViewCellTableViewHeaderView等的描述:

TableViewCell

@property (nonatomic, copy) NSString *identifier;

@property (nonatomic, assign) CGFloat cellHeight;

@property (nonatomic, strong) id data;

CollectionViewCell:

@property (nonatomic, copy) NSString *identifier;

@property (nonatomic, assign) CGSize cellSize;

@property (nonatomic, strong) id data;

TableView的组:

@property (nonatomic, copy) NSString *headerIdentifier;

@property (nonatomic, copy) NSString *footerIdentifier;

@property (nonatomic, strong) NSArray<ZLTableViewRowModel *> *items;

@property (nonatomic, strong) id headerData;

@property (nonatomic, strong) id footerData;

@property (nonatomic, assign) CGFloat headerHeight;

@property (nonatomic, assign) CGFloat footerHeight;

CollectionView的组:


@property (nonatomic, copy) NSString *headerIdentifier;

@property (nonatomic, copy) NSString *footerIdentifier;

@property (nonatomic, strong) NSArray<ZLCollectionViewRowModel *> *items;

@property (nonatomic, strong) id headerData;

@property (nonatomic, strong) id footerData;

@property (nonatomic, assign) CGSize headerSize;

@property (nonatomic, assign) CGSize footerSize;

@property (nonatomic, assign) UIEdgeInsets insets;

@property (nonatomic, assign) CGFloat minimumLineSpacing;

@property (nonatomic, assign) CGFloat minimumInteritemSpacing;

看到这里大家应该都知道我在做什么了吧。。。。虽然不高级,但是用起来真的方便很多了。

统一Cell的赋值方式和注册方式:

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:rowModel.identifier forIndexPath:indexPath];
    if ([cell respondsToSelector:@selector(model)] && rowModel.data) {
        [cell setValue:rowModel.data forKey:@"model"];
    }

对的,Cell就靠model接收传值。

Latest podspec

{
    "name": "LCFastBuildListKit",
    "version": "0.1.9",
    "summary": "u5bf9tableViewu548ccollectionViewu8fdbu884cu7b80u5355u5c01u88c5   u65b9u4fbfu5febu901fu642du5efau8f83u590du6742u7684u5217u8868u9875u9762.",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/jgyhc/LCFastBuildListKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "jgyhc": "[email protected]"
    },
    "source": {
        "git": "https://github.com/jgyhc/LCFastBuildListKit.git",
        "tag": "0.1.9"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "LCFastBuildListKit/Classes/**/*",
    "dependencies": {
        "UITableView+FDTemplateLayoutCell": []
    }
}

Pin It on Pinterest

Share This