美文网首页
iOS:链式编程-tableView组件化

iOS:链式编程-tableView组件化

作者: 豆浆油条cc | 来源:发表于2019-10-28 13:58 被阅读0次

什么是链式编程? 最简单的理解就是通过点语法,调用返回参数为相同对象的方法,通过这种方式,不断的点出方法拼接,最终得出结果。

Masonry,RAC等框架就是通过链式编程实现的。

tableView组件化思考:平常使用tavleView需要实现他的代理及数据源,方法扩散,不方便追踪代码和修改。所以我封装了一个tableView组建,使用链式编程的方式,能够快速实现一个tableView,代理及数据源都是通过block返回代码块,这样一个tableView模块相对高内聚,低耦合。

链式编程-tableview组件化:
https://github.com/qw9685/ccTableView.git

链式编程-collectionView组件化:
https://github.com/qw9685/ccCollectionView.git

Untitled.gif

最简单的实现:

    ccTableView* tableView = [[ccTableView alloc] initPlainTableView:nil reuseIdentifier:@"cellID" frame:self.view.bounds];
    
    tableView.cc_numberOfRows(^NSInteger(NSInteger section, UITableView * _Nonnull tableView) {
        return 5;
    }).cc_ViewForCell(^(NSIndexPath * _Nonnull indexPath, UITableView * _Nonnull tableView, UITableViewCell * _Nonnull cell) {
        cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
        
    }).cc_didSelectRowAtIndexPath(^(NSIndexPath * _Nonnull indexPath, UITableView * _Nonnull tableView) {
        
        [self.navigationController pushViewController:[firstViewController new] animated:YES];
        
    });

自定义cell,header,footer,左滑删除。

    ccTableView* tableView = [[ccTableView alloc] initPlainTableView:[firstTableViewCell class] reuseIdentifier:@"firstTableViewCellID" frame:self.view.bounds];
    
    tableView.cc_commitEditingStylePath(^(NSIndexPath * _Nonnull indexPath, UITableView * _Nonnull tableView, UITableViewCellEditingStyle style) {
        
        NSLog(@"=删除了%ld",(long)indexPath.row);
        
    }).cc_canEditRowAtIndexPath(^BOOL(NSIndexPath * _Nonnull indexPath, UITableView * _Nonnull tableView) {
        return YES;
    }).cc_numberOfRows(^NSInteger(NSInteger section, UITableView * _Nonnull tableView) {
        return 2;
    }).cc_numberOfSections(^NSInteger(UITableView * _Nonnull tableView) {
        return 2;
    }).cc_ViewForFooter(^UIView * _Nonnull(NSInteger section, UITableView * _Nonnull tableView) {
      
        UIView* footerView = [[UIView alloc] init];
        footerView.backgroundColor = [UIColor redColor];
        return footerView;
    }).cc_ViewForHeader(^UIView * _Nonnull(NSInteger section, UITableView * _Nonnull tableView) {
        
        UIView* headerView = [[UIView alloc] init];
        headerView.backgroundColor = [UIColor yellowColor];
        return headerView;
    }).cc_heightForFooter(^NSInteger(NSInteger section, UITableView * _Nonnull tableView) {
        
        return 40;
    }).cc_heightForHeader(^NSInteger(NSInteger section, UITableView * _Nonnull tableView) {
        
        return 20;
    }).cc_heightForCell(^NSInteger(NSIndexPath * _Nonnull indexPath, UITableView * _Nonnull tableView) {
        
        return 100;
    }).cc_ViewForCell(^(NSIndexPath * _Nonnull indexPath, UITableView * _Nonnull tableView, UITableViewCell * _Nonnull cell) {
                
        cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
        
    }).cc_didSelectRowAtIndexPath(^(NSIndexPath * _Nonnull indexPath, UITableView * _Nonnull tableView) {
        NSLog(@"点击了%ld",(long)indexPath.row);
    });

相关文章

  • iOS:链式编程-tableView组件化

    什么是链式编程? 最简单的理解就是通过点语法,调用返回参数为相同对象的方法,通过这种方式,不断的点出方法拼接,最终...

  • iOS:链式编程-collectionView组件化

    链式编程-tableview组件化:https://github.com/qw9685/ccTableView.g...

  • 工作iOS技术总结

    链式编程、函数式、面向接口编程思想 iOS 之ReactiveCocoa 链式编程2 WKWebView的缓存处理...

  • ReactiveObjC入门

    ReactiveObjC基础用法 iOS开发三种编程方式(响应式编程、函数编程、链式编程),函数编程最常用,链式编...

  • 链式编程总结

    链式编程总结 @(iOS) 研究了一下链式编程,但是感觉项目中用处不是很多。 介绍 1.什么时候使用链式编程?在面...

  • iOS组件化

    iOS组件化 iOS组件化

  • iOS 链式编程简单的使用

    iOS 链式编程简单的使用 链式编程-顾名思义,链式,连贯性为其主要特征,放在编程领域来讲,说简单点就是把一系列的...

  • iOS-链式编程思想

    在iOS中,链式编程虽然用的不太多,但是,在特定的应用环境下,利用block实现链式编程的话,会大大的提高编程效率...

  • iOS链式编程

    在iOS中,链式编程虽然用的不太多,但是,在特定的应用环境下,利用block实现链式编程的话,会大大的提高编程效率...

  • iOS组件化方案

    iOS组件化方案 iOS组件化方案

网友评论

      本文标题:iOS:链式编程-tableView组件化

      本文链接:https://www.haomeiwen.com/subject/clmnectx.html