Giter VIP home page Giter VIP logo

yxwlistbinder's Introduction

YXWListBinder

🏁集成

  • podfile 中输入 pod 'YXWListBinder'
  • 执行pod update.

🏃‍♂️开始

提示

  • 该项目依赖于ReactCocoa.
  • 项目中包含TableView和CollectionView的使用Demo.
  • 根据自己的需求实现自己的YXWListBinderWidgetProtocol 和 YXWListBinderViewModelProtocol

实现步骤

  • 头文件声明
#import <YXWListBinder/YXWListBinder.h>
#import <YXWListBinder/YXWListBinderKit.h>
  • 一、创建控制器的ViewModel,继承自YXWBaseViewModel
/*
1.重写- (RACSignal *)requestData:(RACTuple *)tuple;
2.初始化CellModel和HeaderModel(因HeaderModel要实现的协议较多,建议继承自YXWBaseHeaderModel)
3.向self.data中塞入model,并发送出去.
*/

- (RACSignal *)requestData:(RACTuple *)tuple {
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        YXWClassModel *aModel = [YXWClassModel new];
        YXWNibModel *bModel = [YXWNibModel new];
        YXWNibHeaderModel *headerModel = [YXWNibHeaderModel new];
        
        headerModel.subData = [NSMutableArray arrayWithObjects:aModel,bModel, nil];

        for (int i = 0; i<100; i++) {
            YXWNibModel *tModel = [YXWNibModel new];
            [headerModel.subData addObject:tModel];
        }
        
        self.data = [NSMutableArray arrayWithObjects:self.headerModel, nil];
        
        [subscriber sendNext:self.data];
        [subscriber sendCompleted];
        return nil;
    }];
}
  • 二、在控制器ViewDidLoad初始化ViewModel、TableView、YXWListBinder
- (void)viewDidLoad
{
    [super viewDidLoad];

    //初始化Binder
    self.tableViewBinder = [[YXWListBinder alloc] initBinderWithTableView:self.tableView hasSection:YES command:self.viewModel.dataCommand];
    
    [self.tableViewBinder addTableViewDatasSubscribe:^{
    //数据刷新完成后....
    } errorSubcribe:^(NSError *error) {
    //请求错误...
    }];

    //触发viewmodel中的数据请求
    [self.viewModel.dataCommand execute:@(1)];
}
  • 三、Cell中实现bindViewModel方法,绑定数据源.
- (void)bindViewModel:(id<YXWListBinderViewModelProtocol>)viewModel
     sectionViewModel:(id<YXWListBinderViewModelProtocol>)sectionViewModel
          atIndexPath:(NSIndexPath *)indexPath
                first:(BOOL)first
              finally:(BOOL)finally
                extra:(NSDictionary *)extra;
/*
CellModel必须实现的协议.
*/
- (CGFloat)widgetHeight {
    return 高度;
}
    
- (NSString *)identifier {
    return 标识;
}

- (id)showWidget {
    return 要展示的cell class字符串或者nib;
}

🌗 理念

  • 我们大多数构建页面 基本都可以使用TableView 或者 CollectionView来实现,Binder的意义在于使用MVVM模式开发,更注重在ViewModel的数据流的控制来拼装页面的子视图,把ViewController只是作为一个通道。

yxwlistbinder's People

Contributors

xiaowinner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

yxwlistbinder's Issues

使用注意。

示例代码先创建tableview,会导致cell自动计算失效 。 实际使用中先创建tableview然后再initBinder 这样会存在cell 自动计算行高失败。 所以在使用时候要先绑定再写 tableview.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.