Git Product home page Git Product logo

uiscrollview-tdscrollview's Introduction

用最简单的方式处理下拉刷新和空白页面处理

依赖

  • MJRefresh
  • DZNEmptyDataSet

为什么会使用UISCrollView-TDScrollView

  • 如果给一个scrollview添加下拉刷新你可能会这样写

    
    self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
    
    }];
    
    self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
    
    }];
    
  • 当你需要显示空白页面的时候你也许会这样写

        if(list.count == 0){
           empty.hidden = false
        }else{
          empty.hidden = true
        }
    

我认为工程中大量如此的代码,不够美观,不够优雅,所以我觉得应该有更好的实现方式

如何使用

  1. 设置 tableView或者collectionView的delegate

    tableView.tdDelegate = self
    
  2. 实现 TDScrollviewDelegate协议 如果需求只需要下拉刷新那么只需要实现 tdClientBeginRefresh 如果只需要上拉加载更多那么只需要实现tdClientLoadMoreRefresh

    extension HomeParttimeListView:TDScrollviewDelegate{
        func tdClientBeginRefresh() {
          page = 1
        }
        func tdClientLoadMoreRefresh() {
          page = page + 1
        }
    }
  3. 刷新数据(无需关心此时是下拉刷新还是上拉加载更多 请直接调用 td_reload()方法)

     if page == 1 {
                dataSource = source
        }else{
                dataSource.append(contentsOf: source)
       }
    tableView.td_reload(source.count)

解释

  1. td_reload这个方法传入一个count 如果 count=0 那么认为就没有下一页数据了,就会显示没有更多数据

  2. 为什么没有使用gitHub上的 UIScrollView+EmptyDataSet ?因为这个库有bug,我改了下源码 所以如果你的工程里使用了 DZNEmptyDataSet 你可以删除你工程的,使用我这里面的 完全兼容。

  3. 为什么没有制作成pod集成?因为每家公司的下拉刷新显示的空白页面或者默认文案都不一样,你可以把这份代码放到你自己的工程里,根据你公司产品的要求 进行定制。

uiscrollview-tdscrollview's People

Contributors

coder-dongjiayi avatar

Watchers

 avatar

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.