zoukankan      html  css  js  c++  java
  • UITableViewController集成---下拉刷新功能

    iOS 6 之后,UITableViewController添加了一个refreshControl属性,这个属性保持了一个UIRefreshControl的对象指针。

    UIRefreshControl类就是iOS 6 为表示图实现下拉刷新而提供的,UIRefreshControl类目前只能应用于表视图画面。

    - (void)viewDidLoad

    {

      ....

      //  查询请求数据

      action = ACTION_QUERY;

      [self startRequest];

      // 初始化UIRefreshControl

      UIRefreshControl *rc = [[UIRefreshControl  alloc] init ];

      rc.attributedTitle = [[NSAttributedString alloc] initWithString:@"下拉刷新..."] ; 

      [rc addTarget:self  action:@selector(refreshTableView)

                forControlEvents:UIControlEventValueChanged ];

      self.refreshControl = rc ;

    }

    - (void)refreshTableView

    {

      if (self.refreshControl.refreshing)                                                                                                    【1】

      {

        self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"加载中...."];

        // 查询请求

        action = ACTION_QUERY;

        [self startRequest]; // 异步请求完后,调用reloadView方法

      }

    }

    // 异步请求完成后,在请求成功代理方法中调用该方法

    - (void)reloadView:(NSDictionary *)resDict

    {

      [self.refreshControl endRefreshing];                                                                                             【2】

      self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"下拉刷新..."] ;

      ........

    }

    【1】:refreshing属性可以判断控件是否还处于刷新中的状态

    【2】:endRefreshing方法停止刷新 

  • 相关阅读:
    codeforces 673D D. Bear and Two Paths(构造)
    codeforces 673C C. Bear and Colors(暴力)
    codeforces 673B B. Problems for Round(模拟)
    codeforces 673A A. Bear and Game(水题)
    hdu-3555 Bomb(数位dp)
    西交校赛 I. GZP and CS(数位dp)
    西交校赛 F. GZP and Poker
    删除目录下包含“2018” 关键字文件
    CSV转成Excel格式
    解决字符sqlplus 乱码
  • 原文地址:https://www.cnblogs.com/yaoxc/p/3719064.html
Copyright © 2011-2022 走看看