适用于iOS6之后的苹果提供的下拉刷新

一:iOS6.0及以后:

  • 下拉刷新控件UIRefreshControl
  • TableView属性:refreshControl

二:使用

复制代码
 1 - (void)colseTheTB
 2 {
 3     [self dismissViewControllerAnimated:YES completion:nil];
 4 }
 5 
 6 - (void)viewDidLoad
 7 {
 8     [super viewDidLoad];
 9 
10     self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(colseTheTB)];
11     
12     //数据源
13     self.dataArray = [[NSMutableArray alloc]initWithCapacity:10];
14     for (int i = 0; i < 10; i ++) {
15         [_dataArray addObject:[NSString stringWithFormat:@"%d",i]];
16     }
17     
18     
19     //适用于 iOS6 之后,系统自带的下拉刷新控件 UIRefreshControl
20     UIRefreshControl *osRefresh = [[UIRefreshControl alloc]init];
21     osRefresh.tintColor = [UIColor lightGrayColor];
22     osRefresh.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新"];
23     [osRefresh addTarget:self action:@selector(doPullRefresh:) forControlEvents:UIControlEventValueChanged];
24     self.refreshControl = osRefresh;
25 
26 }
27 
28 - (void)doPullRefresh:(UIRefreshControl *)refresh
29 {
30     if (refresh.refreshing) {
31         refresh.attributedTitle = [[NSAttributedString alloc]initWithString:@"正在刷新"];
32         [self performSelector:@selector(handleTheRefresh) withObject:nil afterDelay:2];
33     }
34     
35     else
36     {
37         refresh.attributedTitle = [[NSAttributedString alloc]initWithString:@"释放刷新"];
38 
39     }
40 }
41 
42 - (void)handleTheRefresh
43 {
44     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
45     [formatter setDateFormat:@"MMM d, h:mm:ss a"];
46     NSString *lastUpdated = [NSString stringWithFormat:@"时间:%@", [formatter stringFromDate:[NSDate date]]];
47     self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:lastUpdated] ;
48     
49     static int num = 0;
50     num--;
51     [_dataArray insertObject:[NSString stringWithFormat:@"%d",num] atIndex:0];
52     
53     [self.refreshControl endRefreshing];
54     [self.tableView reloadData];
55 }
复制代码

 三:显示情况

  • 在iOS6上显示情况,请参见 qq for iPhone版本 app
  • 在iOS7 显示情况,是菊花动画,一片一片的铺满
posted @   cocoajin  阅读(662)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示