SVPullToRefresh开源库地址

https://github.com/samvermette/SVPullToRefresh

将整个文件夹SVPullToRefresh拖入工程中并引入头文件即可

注意编译时有一个方法快被弃用了

- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode

工程源码

RootViewController.h

 //  Copyright (c) 2014年 YouXian. All rights reserved.
// #import <UIKit/UIKit.h> @interface RootViewController : UIViewController @end

RootViewController.m

 //  Copyright (c) 2014年 YouXian. All rights reserved.
// #import "RootViewController.h"
#import "SVPullToRefresh.h" @interface RootViewController () <UITableViewDelegate, UITableViewDataSource> @property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource; @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; //初始化 tableView
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds
style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
[self.view addSubview:_tableView]; //初始化数据源
_dataSource = [[NSMutableArray alloc] init];
for (int i = ; i < ; i++)
{
[_dataSource addObject:[NSString stringWithFormat:@"%@", [NSDate date].description]];
} //注册下拉刷新功能
__weak RootViewController *weakSelf = self;
[_tableView addPullToRefreshWithActionHandler:^{
[weakSelf insertRowAtTop];
}]; //注册上拉刷新功能
[_tableView addInfiniteScrollingWithActionHandler:^{
[weakSelf insertRowAtBottom];
}];
} #pragma mark -
#pragma mark PullToRefreshInsertRow - (void)insertRowAtTop
{
int64_t delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//开始更新
[_tableView beginUpdates]; //插入数据到数据源(数组的开头)
[_dataSource insertObject:[NSString stringWithFormat:@"%@", [NSDate date].description]
atIndex:]; //在tableView中插入一行(Row开头)
[_tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:
inSection:]]
withRowAnimation:UITableViewRowAnimationBottom]; //结束更新
[_tableView endUpdates]; //停止菊花
[_tableView.pullToRefreshView stopAnimating];
});
} - (void)insertRowAtBottom
{
int64_t delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//开始更新
[_tableView beginUpdates]; //插入数据到数据源(数组的结尾)
[_dataSource addObject:[NSString stringWithFormat:@"%@", [NSDate date].description]]; //在tableView中插入一行(Row结尾)
[_tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:_dataSource.count -
inSection:]]
withRowAnimation:UITableViewRowAnimationBottom]; //结束更新
[_tableView endUpdates]; //停止菊花
[_tableView.infiniteScrollingView stopAnimating];
});
} #pragma mark -
#pragma mark UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _dataSource.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"Cell";
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:identifier];
} cell.textLabel.text = _dataSource[indexPath.row]; return cell;
} @end

心得:

使用简单,逻辑清晰,开源库使用block实现, RootViewController.m 35行代码处要将RootViewController自身传入block中,需要使用弱应用指针,注意.

工程源码地址:

http://pan.baidu.com/s/1dD24E1V

使用开源库 SVPullToRefresh 实现上拉加载下拉刷新的更多相关文章

  1. APICloud上啦加载下拉刷新模块

    apicloud有自带的上啦加载下拉刷新,当让也可以用第三方或者在模块库里面找一个使用 一.下拉刷新,一下代码写在 apiready = function (){} 里面 apiready = fun ...

  2. Vue mint ui用在消息页面上拉加载下拉刷新loadmore 标记

    之前总结过一个页面存在多个下拉加载的处理方式,今天再来说一下在消息页面的上拉加载和下拉刷新,基本上每个app都会有消息页面,会遇到这个需求 需求:每次加载十条数据,上拉加载下拉刷新,并且没有点击查看过 ...

  3. 上拉加载下拉刷新控件WaterRefreshLoadMoreView

    上拉加载下拉刷新控件WaterRefreshLoadMoreView 效果: 源码: // // SRSlimeView // @author SR // Modified by JunHan on ...

  4. RecyclerView 上拉加载下拉刷新

    RecyclerView 上拉加载下拉刷新 <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/teach_s ...

  5. 微信小程序上拉加载下拉刷新

    微信小程序实现上拉加载下拉刷新 使用小程序默认提供方法. (1). 在xxx.json 中开启下拉刷新,需要设置backgroundColor,或者是backgroundTextStyle ,因为加载 ...

  6. mui scroll和上拉加载/下拉刷新

    mui中 scroll和上拉加载/下拉刷新同时存在会出现两个滚动条 把/*   */ /* //mui页面鼠标拖动代码: mui('.mui-scroll-wrapper').scroll({ dec ...

  7. 基于better-scroll封装一个上拉加载下拉刷新组件

    1.起因 上拉加载和下拉刷新在移动端项目中是很常见的需求,遂自己便基于better-scroll封装了一个下拉刷新上拉加载组件. 2.过程 better-scroll是目前比较好用的开源滚动库,提供很 ...

  8. Flutter上拉加载下拉刷新---flutter_easyrefresh

    前言 Flutter默认不支持上拉加载,下拉刷新也仅仅支持Material的一种样式.Android开发使用过SmartRefreshLayout的小伙伴都知道这是一个强大的刷新UI库,集成了很多出色 ...

  9. SwipeRefreshLayout实现上拉加载下拉刷新

    package com.example.swiperefreshlayoutdemo; import java.util.ArrayList;import java.util.HashMap; imp ...

  10. zepto.js + iscroll.js上拉加载 下拉加载的 移动端 新闻列表页面

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...

随机推荐

  1. IntelliJ IDEA JRebel Maven Tomcat 实现热部署

    一,JRebel 插件 获取与安装 直接在 IDEA 中操作获取 JRebel 插件 Paste_Image.png Paste_Image.png 安装完成,记得重启 IDEA 使刚才安装的插件生效 ...

  2. 配置kotlin自带的编译器,并使用kotlinc、kotlin命令

    Kotlin是一种静态类型的编程语言,可在Java虚拟机上运行,也可以编译为JavaScript源代码. 其主要发展来自位于俄罗斯圣彼得堡的JetBrains程序员团队. 虽然语法与Java不兼容,但 ...

  3. SQL Server 4

    一.视图 1.创建视图 1)选中数据库中的表中的视图处,右键选择新建视图,即: 2)在弹出“添加表”对话框中,单击“表”标签,选择要添加的表,点击添加,即: 3)选中要建立联系的列名的复选框,然后拖动 ...

  4. Dynamic Rankings || 动态/静态区间第k小(主席树)

    JYF大佬说,一星期要写很多篇博客才会有人看 但是我做题没有那么快啊QwQ Part1 写在前面 区间第K小问题一直是主席树经典题=w=今天的重点是动态区间第K小问题.静态问题要求查询一个区间内的第k ...

  5. ORACLE 表空间扩展方法

    ORACLE 表空间扩展方法 环境: linux系统 工具:PL/SQL DEVELOPER 第一步:查看表空间的名字及文件所在位置: select tablespace_name, file_id, ...

  6. 【noip模拟赛1】古韵之乞巧 (dp)

    描述 闺女求天女,更阑意未阑. 玉庭开粉席,罗袖捧金盘. 向月穿针易,临风整线难. 不知谁得巧,明旦试相看. ——祖咏<七夕> 女子乞巧,是七夕的重头戏.古时,女子擅长女红被视为一种重要的 ...

  7. 002.VNC配置部署

    一 安装图形界面 在系统中安装相关图形界面 yum -y install xorg* yum -y install gnome* yum -y install glx*   或者 yum groupi ...

  8. 求有向图的强连通分量个数 之 Kosaraju算法

    代码: #include<cstdio> #include<cstring> #include<iostream> using namespace std; ][] ...

  9. BZOJ.4407.于神之怒加强版(莫比乌斯反演)

    题目链接 Description 求\[\sum_{i=1}^n\sum_{j=1}^m\gcd(i,j)^K\ \mod\ 10^9+7\] Solution 前面部分依旧套路. \[\begin{ ...

  10. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem H. Password Service dp

    Problem H. Password Service 题目连接: http://www.codeforces.com/gym/100253 Description Startups are here ...