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方法停止刷新 

  • 相关阅读:
    Http请求头与响应头
    获取ip位置方法
    简单的Http Server实现
    HTTP
    long、int与byte数组之间的相互转换
    GlusterFS简单配置
    创建线程池
    网络编程socket
    面向对象-进阶篇
    面向对象-初级篇
  • 原文地址:https://www.cnblogs.com/yaoxc/p/3719064.html
Copyright © 2011-2022 走看看