Code Monkey home page Code Monkey logo

jsloadmoreservice's Introduction

JSLoadMoreServiceDemo

CocoaPods Compatible CocoaPods Compatible

让预加载,成为你分页的好朋友

丝滑的样子

images

安装

支持pod 安装 pod 'JSLoadMoreService', '~> 1.1.0'

更新下:pod安装反而会更麻烦,所以遗弃pod,你可以直接拖着JSLoadMoreService文件到你的项目即可,

依赖的三方库有:AFNetworking、ReactiveObjC、YYModel、MJRefresh

使用

优雅的建一个viewmodel类, 然后下面就是怎样调用分类的方法:

    
    RACReplaySubject *subject = [RACReplaySubject subject];
    [[self js_singalForSingleRequestWithURL:Test_Page_URL
                                      para:nil
                                keyOfArray:@"pdlist"
                     classNameOfModelArray:@"JSGoodListModel"
                                  isReload:isReload] subscribeNext:^(id  _Nullable x) {
        /**
         *  x : 分类方法(js_singalForSingleRequestWithURL:...)里 sendNext 传过来的数组
         *  你可以对每次传过来的数组的元素"再加工",知道达到你的要求后 再 sendNext
         */
        //...
        [subject sendNext:x];
    } error:^(NSError * _Nullable error) {
        [subject sendError:error];
    } completed:^{
        /**
         *  走到这里为,每次分页请求所有逻辑处理完毕
         */
        [subject sendCompleted];
    }];
    
    return subject;
}

在你的cellForRowAtIndexPath:代理里选择调用回调

    *  根据当期index计算是否回调preloadblock
    */
    [self preloadDataWithCurrentIndex:indexPath.row];
    ```

优雅的配置tableview的上拉刷新和预加载

```- (JSListTableView *)listTableView{
    
    if (!_listTableView) {
        _listTableView = [[JSListTableView alloc] initWithFrame:self.view.bounds
                                                          style:UITableViewStyleGrouped];
        [self.view addSubview:_listTableView];
        
        kWeakSelf(self)
        /**
         *  刷新
         */
        [_listTableView headerReloadBlock:^{
            kStrongSelf(self)
            [self requestGoodListIsReload:YES];
        }];
        /**
         *  预加载
         */
        _listTableView.js_preloadBlock = ^{
            kStrongSelf(self)
            [self requestGoodListIsReload:NO];
        };
    }
    return _listTableView;
}

新增属性以及方法

/*********************************  多列表分页加载 **********************************/

/**
 *  所有当前数据
 */
@property (nonatomic, strong) NSMutableDictionary                *multiDataDict;
/**
 *  所有当前页码
 */
@property (nonatomic, strong) NSMutableDictionary                *multiCurrentPageDict;
/**
 *  当前列表索引
 */
@property (nonatomic, assign) NSInteger                          currentIndex;
/**
 *  所有当前是否已加载完
 */
@property (nonatomic, strong) NSMutableDictionary                *multiNoMoreDataDict;
/**
 *  所有title数据
 */
@property (nonatomic, strong) NSMutableArray<JSTitleItemModel *> *multiTitleDataArray;
/**
 *  获取当前index下数据
 *
 *  @return 数组
 */
- (NSMutableArray *)getCurrentDataArray;
/**
 *  根据index获取数据
 *
 *  @return 数组
 */
- (NSMutableArray *)getDataArrayWithIndex:(NSInteger)index;
/**
 *  多列表请求分页加载数据
 *
 *  @param baseURL               请求地址
 *  @param para                  请求参数
 *  @param keyOfArray            取数组的key(注:多层请用/分隔)
 *  @param classNameOfModelArray 序列化model的class_name
 *  @param isReload              (YES:刷新、NO:加载更多)
 *
 *  @return RACSingal
 */
- (RACSignal *)js_singalForMultiRequestWithURL:(NSString *)baseURL
                                          para:(NSMutableDictionary *)para
                                    keyOfArray:(NSString *)keyOfArray
                         classNameOfModelArray:(NSString *)classNameOfModelArray
                                      isReload:(BOOL)isReload;

详细的实现步骤请访问我的博客

如果用起来能让你愉悦,别忘记给个star,👍一下~

update:

1.新增多列表混合请求方法以及属性

jsloadmoreservice's People

Contributors

jjosin22 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jsloadmoreservice's Issues

请问为什么要把属性这样扩展起来

  • (BOOL)isNoMoreData{ return [objc_getAssociatedObject(self, &key_isNoMoreData) boolValue]; } - (void)setIsNoMoreData:(BOOL)isNoMoreData{ objc_setAssociatedObject(self, &key_isNoMoreData, @(isNoMoreData), OBJC_ASSOCIATION_ASSIGN); } 请问为什么要把属性这样扩展起来,有什么好处吗?不扩展使用有影响?

看了您的简书文章,感觉封装的挺好

demo对应的http请求无效,看不到结果,

  • @param keyOfArray 取数组的key(注:多层请用/分隔)
  • @param classNameOfModelArray 序列化model的class_name
    上面的两个参数具体代表啥意思呢?keyOfArray值的是返回的json数据格式中的数组的key吗?

不能用Pod...

有很多地方 需要根据自己的需求改动 #warning 此处可以添加统一的HUD 这些地方 都是需要去修改的。

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.