MJRefresh刷新第三方库

MJRefresh刷新第三方库

  1.导入MJRefresh刷新第三方库

  2.导入头文件

#import "MJRefresh.h"

  3.代码的实现(基于大麦网的实例)

-(void)mjrefresh{
    [_tableView addHeaderWithTarget:self action:@selector(refreshact)];
    [_tableView addFooterWithTarget:self action:@selector(refreshact)];
//    [_tableView footerBeginRefreshing];
}

-(void)refreshact{
    [self satarDown];

    [_tableView reloadData];
    [_tableView headerEndRefreshing];
    [_tableView footerEndRefreshing];

}

-(void)satarDown{
    NSString *urlStr = @"http://mapi.damai.cn/proj/HotProj.aspx?CityId=0&source=10099&version=30602";
    _dataArray = [[NSMutableArray alloc]init];

    _request = [[HttpRequest alloc]init];
    [_request requestWithUrl:urlStr target:self action:@selector(dealDowloadFinish:)];
    [_dataArray removeAllObjects];
}

-(void)dealDowloadFinish:(HttpRequest *)request{
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:request.data options:NSJSONReadingMutableContainers error:nil];
    NSArray *arr = dic[@"list"];
    for (NSDictionary *appDic in arr) {
        AppModel *model = [[AppModel alloc]init];
        model.Name = appDic[@"Name"];
        model.Summary = appDic[@"Summary"];
        model.ShowTime = appDic[@"ShowTime"];
        model.VenName = appDic[@"VenName"];
        model.cityname = appDic[@"cityname"];
        model.ProjectID = appDic[@"ProjectID"];
        model.priceName = appDic[@"priceName"];
        [_dataArray addObject:model];
    }

//    结束刷新并且刷新表格
    [_tableView refreshFinished];
    [_tableView loadMoreFinished];
    [_tableView reloadData];
}

参照的代码:

//开始刷新自定义方法
- (void)setupRefresh
{
    //下拉刷新
    [_tableView addHeaderWithTarget:self action:@selector(headerRereshing) dateKey:@"table"];
    [_tableView headerBeginRefreshing];

    // 2.上拉加载更多(进入刷新状态就会调用self的footerRereshing)
    [_tableView addFooterWithTarget:self action:@selector(footerRereshing)];
    //一些设置
    // 设置文字(也可以不设置,默认的文字在MJRefreshConst中修改)
    _tableView.headerPullToRefreshText = @"下拉可以刷新了";
    _tableView.headerReleaseToRefreshText = @"松开马上刷新了";
    _tableView.headerRefreshingText = @"刷新中。。。";

    _tableView.footerPullToRefreshText = @"上拉可以加载更多数据了";
    _tableView.footerReleaseToRefreshText = @"松开马上加载更多数据了";
    _tableView.footerRefreshingText = @"加载中。。。";
}
//下拉刷新
- (void)headerRereshing
{
    //一般这些个里边是网络请求,然后会有延迟,不会像现在刷新这么快
    // 1.添加假数据
    //[_tableViewData insertObject:@"这是刷新的数据" atIndex:0];
    [_tableView reloadData];
    //2.结束刷新
    [_tableView headerEndRefreshing];
}
//上拉加载
- (void)footerRereshing
{
    //这个一般是提取缓存的数据
    // 1.添加假数据
    //[_tableViewData insertObject:@"这是加载以前的数据" atIndex://[_tableViewData count]];
    [_tableView reloadData];
    //2,结束刷新
    [_tableView footerEndRefreshing];
}

实例下载:下载

参考链接:http://www.iashes.com/2015-01-403.html

时间: 2024-08-23 21:54:21

MJRefresh刷新第三方库的相关文章

iOS:详解MJRefresh刷新加载更多数据的第三方库

原文链接:http://www.ios122.com/2015/08/mjrefresh/ 简介 MJRefresh这个第三方库是李明杰老师的杰作,这个框架帮助我们程序员减轻了超级多的麻烦,节约了开发时间,提高了开发效率.由于目前能力有限,尚不能自己写一套框架,所以就先膜拜和看明白大牛的框架了. 用于为应用添加常用的上拉加载更多与下拉刷新效果,适用 UIScrollView . UITableView . UICollectionView . UIWebView. gtihub上的地址:http

上拉刷新和下拉刷新的两种方法(包括使用第三方库MJRefresh)

一.使用苹果原生的方法 1.下拉刷新 2.上拉刷新 (1 首先要新建一个footer得XIB文件,当然同时包括对应的控制器文件,例如在XIB文件中可以如下拖拉对应的控件 (2 然后在代码文件中写一个实例方法 +(instancetype)footer { return  [[[NSBundle mainBundle] loadNibNamed:@"XIB文件名" owner:nil options:nil] lastObject]; } (3 然后在我们的列表控制器中调用: /** *

网络数据的下载(NSUrlconnection异步下载和NSstring同步下载)和UI界面数据的刷新(都是抛弃第三方库的一些本质)

<1>NSString同步下载        //字符串的类方法,会根据url向服务器发起同步的数据请求,并将请求结果作为返回值    //同步请求数据,会对程序的UI主线程造成阻塞,用户体验极差 NSString *str = [NSString stringWithContentsOfURL:[NSURL URLWithString:kUrl] encoding:NSUTF8StringEncoding error:nil];    //json格式的数据 进行json解析 数据最外层是

iOS刷新第三方MJRefresh的基本使用

iOS开发中最好用的刷新第三方框架 MJRefresh GitHub : https://github.com/CoderMJLee/MJRefresh UIRefreshControl的介绍 1,UIRefresh是苹果自带的刷新控件2,支持iOS6.0之后的版本3,一旦被分配到一个UITableViewController,控件的框架是自动管理 UIRefreshControl基本使用 // 刷新中得状态判断,只读属性,根据状态可做一些自定义的事情 @property (nonatomic,

最全面的iOS和Mac开源项目和第三方库汇总

UI 下拉刷新 EGOTableViewPullRefresh – 最早的下拉刷新控件. SVPullToRefresh – 下拉刷新控件. MJRefresh – 仅需一行代码就可以为UITableView或者CollectionView加上下拉刷新或者上拉刷新功能.可以自定义上下拉刷新的文字说明.具体使用看“使用方法”. (国人写) XHRefreshControl – XHRefreshControl 是一款高扩展性.低耦合度的下拉刷新.上提加载更多的组件.(国人写) CBStoreHou

网络中常用的第三方库使用方法汇总

一. SDWebImage使用注意事项------------------------------------------------------------------------------------------------------- 1. 导入SDWebImage第三方库 2. 将Build Settings 中的Compile Sources 里面的所有SD...开头的都加上 -fno-objc-arc(一共需要加5个) 3. 在Info.plist中添加NSAppTranspor

iOS第三方库汇总[转载]

iOS第三方库汇总[转载] 字数2179 阅读334 评论0 喜欢29 简介 此文用于总结,本人使用过或者收藏过的Github第三方类库,以便日后查阅,也便他人借鉴. 资料整理中不定期更新... 开源项目 CodeHub browse and maintain your GitHub repositories on any iOS device! Open-Source iOS Apps 开源iOS apps列表 APP相关 iVersion 提示版本更新 BonMot 字体相关的库,设置字体样

手思3.0 第三方库介绍

手思3.0第三方库介绍 AFNetworking https://github.com/AFNetworking/AFNetworking MBProgressHUD    https://github.com/jdg/MBProgressHUD SVProgressHUD https://github.com/TransitApp/SVProgressHUD SDWebImage   https://github.com/rs/SDWebImage FMDB          https://

iOS 开发第三方库全集

拉刷新 EGOTableViewPullRefresh – 最早的下拉刷新控件. SVPullToRefresh – 下拉刷新控件. MJRefresh – 仅需一行代码就可以为UITableView或者CollectionView加上下拉刷新或者上拉刷新功能.可以自定义上下拉刷新的文字说明.具体使用看"使用方法". (国人写) XHRefreshControl – XHRefreshControl 是一款高扩展性.低耦合度的下拉刷新.上提加载更多的组件.(国人写) CBStoreHo