下拉刷新和上拉加载更多(第三方框架MJRefresh)
#import "RootViewController.h"
#import "MJRefresh.h"
@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate,MJRefreshBaseViewDelegate>
{
UITableView *_tableView ;
NSMutableArray *datas;
MJRefreshHeaderView *headerView;
MJRefreshFooterView *footerView;
}
@end @implementation RootViewController - (void)dealloc
{
[headerView free];
[footerView free];
} - (void)viewDidLoad {
[super viewDidLoad];
//初始化tableView
[self initializeTableView];
// 初始化数据
[self initializeData];
} - (void)initializeTableView
{
_tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
_tableView.dataSource = self;
[self.view addSubview:_tableView];
// 初始化刷新控件
[self initializeRefreshView];
} - (void)initializeRefreshView
{
// 下拉刷新
headerView = [MJRefreshHeaderView header];
headerView.scrollView = _tableView;
headerView.delegate = self; // 上拉加载更多
footerView = [MJRefreshFooterView footer];
footerView.delegate = self;
footerView.scrollView = _tableView;
} /**
* 刷新控件进入开始刷新状态的时候调用
*/
- (void)refreshViewBeginRefreshing:(MJRefreshBaseView *)refreshView
{
if ([refreshView isKindOfClass:[MJRefreshHeaderView class]]) {
//下拉刷新
[self loadNewData];
}else{
[self loadMoreData];
}
}
/*
* 刷新数据
*/
- (void)loadNewData
{
static int count = ;
NSMutableArray *array = [NSMutableArray array];
//每次刷新五条数据
for (int i = ; i < ; i++) {
NSString *str = [NSString stringWithFormat:@"第%d次刷新",count];
[array addObject:str];
}
// 把新数据加到datas前面
NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:array];
[newArray addObjectsFromArray:datas];
datas = newArray;
[_tableView reloadData];
[headerView endRefreshing];
count++;
} /*
* 加载更多数据
*/
- (void)loadMoreData
{
static int count = ;
NSMutableArray *array = [NSMutableArray array];
for (int j = ; j < ; j++) {
NSString *str = [NSString stringWithFormat:@"第%d次加载更多",count];
[array addObject:str];
}
[datas addObjectsFromArray:array];
[_tableView reloadData];
[footerView endRefreshing];
count++;
} - (void)initializeData
{
datas = [NSMutableArray arrayWithObjects:@"A",@"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", nil];
} #pragma mark -配置UITableViewDataSource数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [datas count];
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identify = @"cell";
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:identify];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify]; }
cell.textLabel.text = datas[indexPath.row];
return cell;
} @end
下拉刷新和上拉加载更多(第三方框架MJRefresh)的更多相关文章
- juery下拉刷新,div加载更多元素并添加点击事件(二)
buffer.append("<div class='col-xs-3 "+companyId+"' style='padding-left: 10px; padd ...
- android--------自定义控件ListView实现下拉刷新和上拉加载
开发项目过程中基本都会用到listView的下拉刷新和上滑加载更多,为了方便重写的ListView来实现下拉刷新,同时添加了上拉自动加载更多的功能. Android下拉刷新可以分为两种情况: 1.获取 ...
- Android 自定义 ListView 上下拉动“刷新最新”和“加载更多”歌曲列表
本文内容 环境 测试数据 项目结构 演示 参考资料 本文演示,上拉刷新最新的歌曲列表,和下拉加载更多的歌曲列表.所谓"刷新最新"和"加载更多"是指日期.演示代码 ...
- IOS 开发下拉刷新和上拉加载更多
IOS 开发下拉刷新和上拉加载更多 简介 1.常用的下拉刷新的实现方式 (1)UIRefreshControl (2)EGOTTableViewrefresh (3)AH3DPullRefresh ( ...
- 实现RecyclerView下拉刷新和上拉加载更多以及RecyclerView线性、网格、瀑布流效果演示
实现RecyclerView下拉刷新和上拉加载更多以及RecyclerView线性.网格.瀑布流效果演示 效果预览 实例APP 小米应用商店 使用方法 build.gradle文件 dependenc ...
- vue2.0 自定义 下拉刷新和上拉加载更多(Scroller) 组件
1.下拉刷新和上拉加载更多组件 Scroller.vue <!-- 下拉刷新 上拉加载更多 组件 --> <template> <div :style="mar ...
- 手把手教你实现RecyclerView的下拉刷新和上拉加载更多
手把手教你实现RecyclerView的下拉刷新和上拉加载更多 版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明. 本文链接:https:// ...
- RecyclerView下拉刷新和上拉加载更多实现
RecyclerView下拉刷新和上拉加载更多实现 转 https://www.jianshu.com/p/4ea7c2d95ecf 在Android开发中,RecyclerView算是使用频率非 ...
- Android 5.X新特性之为RecyclerView添加下拉刷新和上拉加载及SwipeRefreshLayout实现原理
RecyclerView已经写过两篇文章了,分别是Android 5.X新特性之RecyclerView基本解析及无限复用 和 Android 5.X新特性之为RecyclerView添加Header ...
- iscroll.js 下拉刷新和上拉加载
html代码如下 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...
随机推荐
- 25 python socket网络编程
一 客户端/服务器架构 1.硬件C/S架构(打印机) 2.软件C/S架构 互联网中处处是C/S架构 如黄色网站是服务端,你的浏览器是客户端(B/S架构也是C/S架构的一种) 腾讯作为服务端为你提供视频 ...
- java学习笔记--常用类
一.Math类:针对数学运算进行操作的类 1.常用的方法 A:绝对值 public static int abs(int a) B:向上取整 public static double ceil( ...
- 2018.8.10 programming bat based on python
@echo off REM Current DevProg Version. Match the pip package version (x.y.z)SET currentversion=0.4.0 ...
- CodeForces - 138C: Mushroom Gnomes - 2 (线段树&概率&排序)
One day Natalia was walking in the woods when she met a little mushroom gnome. The gnome told her th ...
- DataTable:数据库到程序的桥梁
DataTable:是一个临时保存数据的网格虚拟表(表示内存中数据的一个表.).DataTable是ADO dot net 库中的核心对象,它无须代码就可以简单的绑定数据库,它具有微软风格的用户界面. ...
- vue 链接
https://www.jianshu.com/p/5d9b341d650f vue-cli入门(三)——人员管理实例 ps:如何创建vue-cli项目 https://www.v2ex.com/t/ ...
- Unity3D的SystemInfo类,用于获取运行设备硬件信息(CPU、显卡、类型等)
SystemInfo类中的静态变量: 中文显示: Rendering.CopyTextureSupport copyTextureSupport:(只读)支持多种复制纹理功能的情况. string ...
- 2、Monkey简单使用
1.使用Monkey测试,前提是有虚拟机或者真机设备,查看是否有设备存在:adb devices (需要先进入SDK的tool目录下才执行该操作) 2.查看设备上各个包名 adb shell pm l ...
- 日志管理系统ELK6.2.3
https://www.jianshu.com/p/88f2cbedcc2a 写在前面 刚毕业工作的时候,处理日志喜欢自己写脚本抓取数据分析日志,然后在zabbix上展示出来.但是开发要看日志的时候, ...
- Northwind 示例数据库
Northwind 示例数据库 Northwind Traders 示例数据库包含一个名为 Northwind Traders 的虚构公司的销售数据,该公司从事世界各地的特产食品进出口贸易. 下载地址 ...