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. (10) openssl dhparam(密钥交换)

    openssl dhparam用于生成和管理dh文件.dh(Diffie-Hellman)是著名的密钥交换协议,或称为密钥协商协议,它可以保证通信双方安全地交换密钥. 但注意,它不是加密算法,所以不提 ...

  2. elementary 5.0 安装 chrome

    sudo apt install google-chrome-stable wget -q -O - https://dl.google.com/linux/linux_signing_key.pub ...

  3. JavaScript基础对象---Number

    一.创建Number实例对象 /** * new Number(value); * value 被创建对象的数字值 * * Number 对象主要用于: 如果参数无法被转换为数字,则返回 NaN. 在 ...

  4. DEVExpress中BarItem的使用2

    没有验证LookUpEdit与ComBox的区别. 没有验证ZoomTrackBarControl的使用方法. SparkLine看着也蛮有趣,需要绑定数据源控件的均没有验证. 前一节介绍的BarIt ...

  5. python3 时间复杂度

    时间复杂度 (1)时间频度 一个算法执行所耗费的时间,从理论上是不能算出来的,必须上机运行测试才能知道.但我们不可能也没有必要对每个算法都上机测试,只需知道哪个算法花费的时间多,哪个算法花费的时间少就 ...

  6. 【链表】2017多校训练三 HDU 6058 Kanade's sum

    acm.hdu.edu.cn/showproblem.php?pid=6058 [题意] 给定一个排列,计算 [思路] 计算排列A中每个数的贡献,即对于每个ai,计算有ni个区间满足ai是区间中的第k ...

  7. 把disable maven nature后的项目,恢复菜单呈现出来(Convert to Maven Project)

    把disable maven nature后的项目,恢复菜单呈现出来(Convert to Maven Project) 有的时候需求把disable maven nature后的项目,再转换为mav ...

  8. castle problem——(深度优先搜索,递归实现和stack实现)

    将问题的各状态之间的转移关系描述为一个图,则深度优先搜索遍历整个图的框架为:Dfs(v) {if( v 访问过)return;将v标记为访问过;对和v相邻的每个点u: Dfs(u);}int main ...

  9. WordPress 权限方案

    每个主机和主机的情况可能有所差异,如下只是概括性地描述,并不一定适用于所有情况.它只适用于进行“常规设置”的情况(注:比如通过“suexec”方式来进行共享主机的,详情见下方) 通常,所有文件是由您的 ...

  10. c++ 高性能日志库(muduo_AsyncLogging)

    c++ 高性能日志库(muduo_AsyncLogging) 实现一个高效的网络日志库要解决那些问题? 首先明确一下问题的模型,这是一个典型的多生产者 单消费者问题,对于前端的日志库使用者来说,应该做 ...