#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)的更多相关文章

  1. juery下拉刷新,div加载更多元素并添加点击事件(二)

    buffer.append("<div class='col-xs-3 "+companyId+"' style='padding-left: 10px; padd ...

  2. android--------自定义控件ListView实现下拉刷新和上拉加载

    开发项目过程中基本都会用到listView的下拉刷新和上滑加载更多,为了方便重写的ListView来实现下拉刷新,同时添加了上拉自动加载更多的功能. Android下拉刷新可以分为两种情况: 1.获取 ...

  3. Android 自定义 ListView 上下拉动“刷新最新”和“加载更多”歌曲列表

    本文内容 环境 测试数据 项目结构 演示 参考资料 本文演示,上拉刷新最新的歌曲列表,和下拉加载更多的歌曲列表.所谓"刷新最新"和"加载更多"是指日期.演示代码 ...

  4. IOS 开发下拉刷新和上拉加载更多

    IOS 开发下拉刷新和上拉加载更多 简介 1.常用的下拉刷新的实现方式 (1)UIRefreshControl (2)EGOTTableViewrefresh (3)AH3DPullRefresh ( ...

  5. 实现RecyclerView下拉刷新和上拉加载更多以及RecyclerView线性、网格、瀑布流效果演示

    实现RecyclerView下拉刷新和上拉加载更多以及RecyclerView线性.网格.瀑布流效果演示 效果预览 实例APP 小米应用商店 使用方法 build.gradle文件 dependenc ...

  6. vue2.0 自定义 下拉刷新和上拉加载更多(Scroller) 组件

    1.下拉刷新和上拉加载更多组件 Scroller.vue <!-- 下拉刷新 上拉加载更多 组件 --> <template> <div :style="mar ...

  7. 手把手教你实现RecyclerView的下拉刷新和上拉加载更多

    手把手教你实现RecyclerView的下拉刷新和上拉加载更多     版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明. 本文链接:https:// ...

  8. RecyclerView下拉刷新和上拉加载更多实现

    RecyclerView下拉刷新和上拉加载更多实现 转 https://www.jianshu.com/p/4ea7c2d95ecf   在Android开发中,RecyclerView算是使用频率非 ...

  9. Android 5.X新特性之为RecyclerView添加下拉刷新和上拉加载及SwipeRefreshLayout实现原理

    RecyclerView已经写过两篇文章了,分别是Android 5.X新特性之RecyclerView基本解析及无限复用 和 Android 5.X新特性之为RecyclerView添加Header ...

  10. iscroll.js 下拉刷新和上拉加载

    html代码如下 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

随机推荐

  1. nexus上传jar带依赖

    编写pom文件 比如我上传alipay-sdk-java.jar   依赖是commons-logging.jar <project> <modelVersion>1.3.1& ...

  2. cassandra mongodb选择——cassandra:分布式扩展好,写性能强,以及可以预料的查询;mongodb:非事务,支持复杂查询,但是不适合报表

    Of course, like any technology MongoDB has its strengths and weaknesses. MongoDB is designed for OLT ...

  3. LeetCode OJ:Contains Duplicate III(是否包含重复)

    Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...

  4. FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

    hive启动后,出现以下异常 hive> show databases; FAILED: Error / failed on connection exception: java.net.Con ...

  5. @angular/cli项目构建--httpClient

    app.module.ts update imports: [ HttpClientModule] product.component.ts import {Component, OnInit} fr ...

  6. 轮廓Outline|表格Table实例

    1.使用outline属性在元素周围画一条线. border:red solid thin; outline:#00ff00 dotted thick; outline-style:dotted|da ...

  7. Java实现LSH(Locality Sensitive Hash )

    在对大批量数据进行图像处理的时候,比如说我提取SIFT特征,数据集为10W张图片,一个SIFT特征点是128维,一张图片提取出500个特征点,这样我们在处理的时候就是对5000万个128维的数据进行处 ...

  8. UVALive - 5031 Graph and Queries (并查集+平衡树/线段树)

    给定一个图,支持三种操作: 1.删除一条边 2.查询与x结点相连的第k大的结点 3.修改x结点的权值 解法:离线倒序操作,平衡树or线段树维护连通块中的所有结点信息,加个合并操作就行了. 感觉线段树要 ...

  9. C#进阶之路(三):深拷贝和浅拷贝

    一.前言 本文主要讨论深浅拷贝的区别,如果实现.浅拷贝日常的应用比较懂,这里不做深入讨论,那么深拷贝如何实现?目前我知道的方式有三种:反射,反序列化和表达树的方式.这里需要注意如果用反射来实现深拷贝的 ...

  10. Python 列表的切片和连接

    一.定义一个list >>> a = [1, 3, 4, 5, 'a', 's'] >>> a [1, 3, 4, 5, 'a', 's'] 二.获取列表中前3个元 ...