下拉刷新和上拉加载更多(第三方框架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"> < ...
随机推荐
- logz.io一个企业级的ELK日志分析器 内部集成了机器学习识别威胁——核心:利用用户对于特定日志事件的反馈处理动作来学习判断日志威胁 + 类似语音识别的专家系统从各方收集日志威胁信息
转自: 可看到它使用机器学习算法来识别DNS安全问题 http://logz.io/blog/machine-learning-log-analytics/ A Machine Learning Ap ...
- mac上获取手机的uuid
把手机连上mac 终端中输入: system_profiler SPUSBDataType | grep "Serial Number:.*" 修改用 | sed s#" ...
- XML DOM - Range 对象
Range对象 Range对象表示文档的连续范围区域,如用户在浏览器窗口中用鼠标拖动选中的区域. dom标准Range对象 在IE中使用TextRange对象 range对象常用的建立方法在开发中 ...
- C++中string的常见用法
在ACM中主要用到string的这几个功能:赋值,添加,删除,替换,查找,比较,反向排序. 1.赋值 直接来就行: string ss; ss="aaa"; 或者 string s ...
- 如何显示PHP运行错误
在运行文件的最前面加两行代码: error_reporting(E_ALL); ini_set('display_errors', '1'); 这样调试起来就方便多了
- 现网CPU飙高,Full GC告警
现网CPU飙高,Full GC告警 https://www.cnblogs.com/QG-whz/p/9647614.html 问题出现:现网CPU飙高,Full GC告警 CGI 服务发布到现网后, ...
- LeetCode Max Consecutive Ones II
原题链接在这里:https://leetcode.com/problems/max-consecutive-ones-ii/ 题目: Given a binary array, find the ma ...
- shell split函数的使用
#!/bin/awk -f BEGIN{FS=","} {split($1,name," "); for (i in name) print name[i] }
- 安装webpack
首先要安装 Node.js, Node.js 自带了软件包管理器 npm,Webpack 需要 Node.js v0.6 以上支持,建议使用最新版 Node.js. 用 npm 安装 Webpack: ...
- nginx 400
做服务器nginx配置的时候有出现过 400 Bad Request 服务器无法理解请求的格式,客户端不应当尝试再次使用相同的内容发起请求.