MJRefresh实现刷新(使用它的Block方法)

 
//
// YFMVCPostListViewController.m
// iOS122
//
// Created by 颜风 on 15/10/14.
// Copyright (c) 2015年 iOS122. All rights reserved.
// #import "YFMVCPostListViewController.h"
#import "YFArticleModel.h"
#import <AFNetworking.h>
#import <MJRefresh.h>
#import <MBProgressHUD.h>
#import "YFMVCPostViewController.h" @interface YFMVCPostListViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView * tableView;
@property (nonatomic, strong) NSMutableArray * articles; //!< 文章数组,内部存储AFArticleModel类型.
@property (assign, nonatomic) NSInteger page; //!< 数据页数.表示下次请求第几页的数据. @end @implementation YFMVCPostListViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
} - (NSMutableArray *)articles
{
if (nil == _articles) {
_articles = [NSMutableArray arrayWithCapacity: 42];
} return _articles;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear: animated]; // 马上进入刷新状态
[self.tableView.header beginRefreshing];
} - (UITableView *)tableView
{
if (nil == _tableView) {
_tableView = [[UITableView alloc] init]; [self.view addSubview: _tableView]; [_tableView makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
}]; _tableView.delegate = self;
_tableView.dataSource = self; NSString * cellReuseIdentifier = NSStringFromClass([UITableViewCell class]); [_tableView registerClass: NSClassFromString(cellReuseIdentifier) forCellReuseIdentifier:cellReuseIdentifier]; _tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
self.page = 0; [self updateData];
}]; _tableView.footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
[self updateData];
}]; } return _tableView;
} /**
* 更新视图.
*/
- (void) updateView
{
[self.tableView reloadData];
}
/**
* 停止刷新
*/
-(void)endRefresh{
[self.tableView.header endRefreshing];
[self.tableView.footer endRefreshing];
}
/**
* 更新数据.
*
* 数据更新后,会自动更新视图.
*/ - (void)updateData
{
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSString * urlStr = [NSString stringWithFormat: @"http://www.ios122.com/find_php/index.php?viewController=YFPostListViewController&model[category]=%@&model[page]=%ld", self.categoryName, (long)self.page ++]; [manager GET: urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { [self endRefresh]; if (1 == self.page) { // 说明是在重新请求数据.
self.articles = nil;
} NSArray * responseArticles = [YFArticleModel objectArrayWithKeyValuesArray: responseObject]; [self.articles addObjectsFromArray: responseArticles]; [self updateView];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self endRefresh]; MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = @"您的网络不给力!";
[hud hide: YES afterDelay: 2]; }];
} # pragma mark - tabelView代理方法. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger number = self.articles.count; return number;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * cellReuseIdentifier = NSStringFromClass([UITableViewCell class]); UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: cellReuseIdentifier forIndexPath:indexPath]; YFArticleModel * model = self.articles[indexPath.row]; NSString * content = [NSString stringWithFormat: @"标题:%@ 内容:%@", model.title, model.desc]; cell.textLabel.text = content; cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// 跳转到博客详情.
YFArticleModel * articleModel = self.articles[indexPath.row]; YFMVCPostViewController * postVC = [[YFMVCPostViewController alloc] init]; postVC.articleID = articleModel.id; [self.navigationController pushViewController: postVC animated: YES];
} @end

MJRefresh实现刷新(使用它的Block方法)的更多相关文章

  1. 弃用的异步get和post方法之Block方法

    #import "ViewController.h" #import "Header.h" @interface ViewController () <N ...

  2. 使用CSS中的meta实现web定时刷新或跳转的方法

    这篇文章主要介绍了使用CSS中的meta实现web定时刷新或跳转的方法,比使用JavaScript脚本实现起来更加简单一些,需要的朋友可以参考下 meta源信息功能之页面定时跳转与刷新 几乎所有的网页 ...

  3. Javascript刷新页面的几种方法

    Javascript刷新页面的几种方法: window.navigate(location)location.reload()location=locationlocation.assign(loca ...

  4. Javascript刷新页面的八种方法

    /** * Javascript刷新页面的八种方法 * 说明一下,jQuery没有发现刷新页面的方法. */ 1 history.go(0) 2 location.reload() 3 locatio ...

  5. JS刷新页面的几种方法(转)

    Javascript刷新页面的几种方法: 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(locat ...

  6. Javascript刷新页面的几种方法:

    Javascript刷新页面的几种方法: 1    history.go(0) 2    window.location.reload() window.location.reload(true)  ...

  7. JS刷新当前页面的几种方法总结

    reload 方法,该方法强迫浏览器刷新当前页面. 语法:location.reload([bForceGet]) 参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里取当前页 ...

  8. C# Winform频繁刷新导致界面闪烁解决方法

    C#Winform频繁刷新导致界面闪烁解决方法 一.通过对窗体和控件使用双缓冲来减少图形闪烁(当绘制图片时出现闪烁时,使用双缓冲) 对于大多数应用程序,.NET Framework 提供的默认双缓冲将 ...

  9. winform频繁刷新导致界面闪烁解决方法

    转自龙心文 原文 winform频繁刷新导致界面闪烁解决方法 一.通过对窗体和控件使用双缓冲来减少图形闪烁(当绘制图片时出现闪烁时,使用双缓冲) 对于大多数应用程序,.NET Framework 提供 ...

随机推荐

  1. centos7 中源码安装nginx

    使用nginx有一段时间了,还是有很多东西不懂的,在这里做一下自己学习过程中的一些整理,能使自己得到提升. 1.环境:centos7 1511  最小化安装 2.下载nginx,可以在系统中下载,也可 ...

  2. 常见的User-Agent

    User_Agent = ["Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_2 like Mac OS X; zh-cn) AppleWebKit/533. ...

  3. python 03 8/25-8/27 range 、randint

    import random """字符串的操作中 三种方法,只包含左索引,不包含右索引""" hi= "bokeyuan pyth ...

  4. 对于easyui $.messager.alert和 $.messager.confirm 不同浏览器中位置控制

    $.messager.confirm({ title: '种子购买', msg: '确定购买这个'+seedName+'的种子嘛?', top:, fn: function (r) { if (r){ ...

  5. centos挂载本地镜像作为yum源

    1.安装Centos后默认的Yum源如下 ll /etc/yum.repos.d/   [root@localhost ~]# ll /etc/yum.repos.d/ total 32 -rw-r- ...

  6. python操作剪贴板错误提示:pywintypes.error: (1418, 'GetClipboardData',线程没有打开的剪贴板)

    问题现象:通过打断点,一步步调试可以正常复制和粘贴剪贴板数据.但是直接运行会报错pywintypes.error: (1418, 'GetClipboardData',线程没有打开的剪贴板) 问题原因 ...

  7. BZOJ 2561: 最小生成树【最小割/最大流】

    Description 给定一个边带正权的连通无向图G=(V,E),其中N=|V|,M=|E|,N个点从1到N依次编号,给定三个正整数u,v,和L (u≠v),假设现在加入一条边权为L的边(u,v), ...

  8. PHP日历程序编写(简单实现)

    <meta charset="utf-8"><?php $year = isset($_GET['year']) ? $_GET['year'] : date(& ...

  9. POJ 2348 Euclid's Game【博弈】

    题目链接: http://poj.org/problem?id=2348 题意: 给定两个数,两个人每次从较大数中减去较小数的倍数,谁先得到0谁获胜,为谁赢? 分析: 令一种可能出现的整数对为(a,b ...

  10. T1365 浴火银河星际跳跃 codevs

    http://codevs.cn/problem/1365/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description 小 K 又在玩浴 ...