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

posted @ 2014-05-09 15:47  Big.Eagle  阅读(311)  评论(0编辑  收藏  举报