zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    一个主板上连接两个都有引导的盘
    pytorch查看模型weight与grad
    linux终端窗口字体缩放快捷键
    vim选中多行缩进(python多行缩进)与删除多行前面的空格
    python import 包的路径以及相对路径加载的问题
    pycharm中添加PATH变量
    Atom选中多行操作
    php扩展 swoole的安装与使用
    12121212
    linux系统下清理所有Redis缓存
  • 原文地址:https://www.cnblogs.com/BadMao/p/4393782.html
Copyright © 2011-2022 走看看