ios 下拉刷新
2016-02-25 00:00
288 查看
- (void)viewDidLoad { [super viewDidLoad]; // 集成刷新控件 [self setupRefresh]; } /** * 集成下拉刷新 */ -(void)setupRefresh { //1.添加刷新控件 UIRefreshControl *control=[[UIRefreshControl alloc]init]; [control addTarget:self action:@selector(refreshStateChange:) forControlEvents:UIControlEventValueChanged]; [self.tableView addSubview:control]; //2.马上进入刷新状态,并不会触发UIControlEventValueChanged事件 [control beginRefreshing]; // 3.加载数据 [self refreshStateChange:control]; }
/** * UIRefreshControl进入刷新状态:加载最新的数据 */ -(void)refreshStateChange:(UIRefreshControl *)control { // 3.发送请求 AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager]; [mgr GET:@"https://api.weibo.com/2/statuses/public_timeline.json" parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject){ //1.获取数据,处理数据,传递数据给tableView,如: // 将最新的微博数据,添加到总数组的最前面 // NSRange range = NSMakeRange(0, newStatuses.count); // NSIndexSet *set = [NSIndexSet indexSetWithIndexesInRange:range]; // [self.statuses insertObjects:newStatuses atIndexes:set]; //2.刷新表格 [self.tableView reloadData]; // 3. 结束刷新 [control endRefreshing]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { // 结束刷新刷新 ,为了避免网络加载失败,一直显示刷新状态的错误 [control endRefreshing]; }]; }
相关文章推荐
- ios 异步加载图片结合tableView SDWebImage
- iOS开发笔记
- iOS新的视频开发框架AVPlayerViewContoller与画中画技术
- 关于iOS上的对象映射公用方法-备
- iOS推送 再备
- iOS中定时器NSTimer的使用-备用
- 在iOS开发中使用FMDB-备用
- 蓝懿ios微博项目之发送信息
- 详解ios文件系统文件目录读写操作-备用
- iOS 摇一摇的实现-备用
- iOS绘图教程
- iOS 第三方库 - Masonry
- iOS 第三方库 - MJRefresh
- iOS 第三方库 - MJExtension
- iOS 第三方库 - FastCoding
- iOS NSDictionary、NSData、JSON等 数据类型相互转换
- 常用第三方库与框架
- iOS 第三方库 - MBProgressHUD
- iOS开发CocoaPods使用
- IOS 布局