新浪微博客户端(18)-集成下拉刷新控件UIRefreshControl
HomeViewController.m
- (void)setupPullToRefreshView {
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refreshNewData:) forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:refreshControl];
}
#pragma mark - UIRefreshContorl 监听方法
- (void)refreshNewData:(UIRefreshControl *)control {
AFHTTPSessionManager *requestManager = [AFHTTPSessionManager manager];
NSString *urlString = @"https://api.weibo.com/2/statuses/friends_timeline.json";
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"access_token"] = [DJAccountTool account].access_token;
DJStatus *status = [self.statuses firstObject];
if (status) {
params[@"since_id"] = status.idstr;
}
[requestManager GET:urlString parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary * _Nullable responseObject) {
NSArray *newStatuses = [DJStatus mj_objectArrayWithKeyValuesArray:responseObject[@"statuses"]];
// 将刷新获取到的新数据添加到总数组的头部
NSRange range = NSMakeRange(, newStatuses.count);
NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndexesInRange:range];
[self.statuses insertObjects:newStatuses atIndexes:indexSet];
// 刷新TableView
[self.tableView reloadData];
// 隐藏RefreshControl
[control endRefreshing];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[control endRefreshing]; // 当数据获取失败时结束刷新操作
}];
}
最终效果:

新浪微博客户端(18)-集成下拉刷新控件UIRefreshControl的更多相关文章
- iOS:下拉刷新控件UIRefreshControl的详解
下拉刷新控件:UIRefreshControl 1.具体类信息: @interface UIRefreshControl : UIControl //继承控制类 - (instancetype)ini ...
- IOS6.0自带下拉刷新控件UIRefreshControl
1.UIRefreshControl必需要在IOS6.0以后才干使用,同一时候他仅仅能在UITableViewController类中才干够使用 2.使用比較简单 self.refreshContro ...
- Android——谷歌官方下拉刷新控件SwipeRefreshLayout(转)
转自:http://blog.csdn.net/zouzhigang96/article/details/50476402 版权声明:本文为博主原创文章,未经博主允许不得转载. 前言: 如今谷歌推出了 ...
- android官方下拉刷新控件SwipeRefreshLayout的使用
可能开发安卓的人大多数都用过很多下拉刷新的开源组件,但是今天用了官方v4支持包的SwipeRefreshLayout觉得效果也蛮不错的,特拿出来分享. 简介:SwipeRefreshLayout组件只 ...
- [Android]下拉刷新控件RefreshableView的实现
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4172483.html 需求:自定义一个ViewGroup,实现 ...
- android SwipeRefreshLayout google官方下拉刷新控件
下拉刷新功能之前一直使用的是XlistView很方便我前面的博客有介绍 SwipeRefreshLayout是google官方推出的下拉刷新控件使用方法也比较简单 今天就来使用下SwipeRefres ...
- Android PullToRefresh下拉刷新控件的简单使用
PullToRefresh这个开源库早就听说了,不过一直没用过.作为一个经典的的开源库,我觉得还是有必要认识一下. 打开github上的网址:https://github.com/chrisbanes ...
- Android SwipeRefreshLayout 官方下拉刷新控件介绍
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24521483 下面App基本都有下拉刷新的功能,以前基本都使用XListView ...
- Google SwipeRefreshLayout(Goolge官方下拉刷新控件)尝鲜
前天Google官方终于出了Android刷新控件——SwipeRefreshLayout. 使用前先需要将android.support.v4.jar升级到19.1.升级后,可能会出现SDK版本与A ...
随机推荐
- [CareerCup] 4.5 Validate Binary Search Tree 验证二叉搜索树
4.5 Implement a function to check if a binary tree is a binary search tree. LeetCode上的原题,请参见我之前的博客Va ...
- [CareerCup] 8.9 An In-memory File System 内存文件系统
8.9 Explain the data structures and algorithms that you would use to design an in-memory file system ...
- [MetaHook] Quake Bink function
If you want to play Bink video in game, maybe you need this code. QBink.h #ifndef QBINK_H #define QB ...
- java数据类型总结
java8大基本数据类型: 整型: byte 字节型 1字节 数据范围:-27 ~ 27- 1 即:-128 ~ 127 short 短整型 2字节 数据范围:-215 ~ ...
- [codevs 1503]愚蠢的宠物(特殊的LCA)
题目:http://codevs.cn/problem/1503/ 分析:一道裸的LCA,但是由于询问只有一次,所以可以简单打打……可以从a,b向父节点推直到1节点,然后比较两个序列,后面一段肯定相同 ...
- 第十六章:脚本化HTTP
写在本章内容前: 第十五章:事件处理 涉及到到较多的文字篇幅,介于个人精力问题,暂不更新.主要包含的内容有事件类型.注册事件处理程序.事件处理程序的调用.文档加载事件.鼠标事件.鼠标滚轮事件.拖放事件 ...
- linux 添加永久ip、路由和开启路由功能
一.添加永久ip 编辑/etc/sysconfig/network-scripts/ifcfg-eth0文件: 网络接口配置文件 [root@localhost ~]# cat /etc/syscon ...
- 每天一个linux命令(21):tar命令
通过SSH访问服务器,难免会要用到压缩,解压缩,打包,解包等,这时候tar命令就是是必不可少的一个功能强大的工具.linux中最流行的tar是麻雀虽小,五脏俱全,功能强大. tar 命令可以为linu ...
- window下为apache配置ssl证书
转载自 子非鱼 的博客稍作修改 第一步:依赖 配置Apache服务器支持https协议和SSL证书,最基本的要求是Apache包含openssl模块.还好apache/bin目录下有libeay32. ...
- 解决系统打开CHM文件无法正常显示
最近学习servlet下载了一个CHM的帮助手册但是打开后右侧却时空白.试了各种方法都没有成功最后终于找到原因所在. 一般情况下无法显示网页:右键 chm文件属性里最下面有个“解除锁定”,点击“解除锁 ...