zoukankan      html  css  js  c++  java
  • 适用于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 显示情况,是菊花动画,一片一片的铺满
  • 相关阅读:
    springboot-web进阶(四)——单元测试
    Java Programming Language Enhancements
    浅谈现代编程语言语法与标准库紧绑定现象
    Objective-C如何自己实现一个基于数组下标的属性访问模式
    Objective-C如何自己实现一个for-each语法形式
    Objective-C中的self与LLVM Clang新引入的instancetype
    在Win7下玩PC游戏发生类似d3d9x_43.dll找不到的情况
    x86架构64位模式下的寄存器列表
    OpenCL如何判定一个work-group的最大Local Memory大小
    关于一个GPGPU优化中Bank Conflict的讨论
  • 原文地址:https://www.cnblogs.com/cocoajin/p/3490632.html
Copyright © 2011-2022 走看看