博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios 下拉刷新
阅读量:7232 次
发布时间:2019-06-29

本文共 1462 字,大约阅读时间需要 4 分钟。

hot3.png

- (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];    }];}

转载于:https://my.oschina.net/u/554046/blog/620823

你可能感兴趣的文章
nginx常用命令
查看>>
ASP.NET 无权访问所请求的资源。请考虑对 ASP.NET 请求标识授予访问此资源的权限。...
查看>>
GridView中字符串太长处理方式
查看>>
侧滑动画
查看>>
20175318 2018-2019-2 实验二《Java面向对象程序设计》实验报告
查看>>
自定义控件的最基本了解和应用
查看>>
题解 CF191C 【Fools and Roads】
查看>>
phpStudy配置多站点多域名步骤,及遇到的403错误解决方式
查看>>
Fiddler (二) Script 用法
查看>>
js学习笔记之自调用函数和原型链
查看>>
angularjs4+ionic3集成搭建
查看>>
JSP学习-02隐式对象
查看>>
jQuery对象和DOM对象的相互转换
查看>>
jQuery动画
查看>>
云备胎与观察者模式
查看>>
反射工厂模式
查看>>
网络打印机拒绝访问,无法连接处理方法汇总
查看>>
SQL Server 表压缩
查看>>
HDU-3549 Flow Problem 简单最大流
查看>>
HDU-2102 A计划 BFS
查看>>