iOS UIRefreshControl的使用 示例

 UIRefreshControl目前只能用于UITableViewController

UITableViewController已经声明了UIRefreshControl,但是还没有初始化,所以需要我们自己初始化


在talbeViewController中 直接调用refreshControl 初始化

  self.refreshControl = [[UIRefreshControl alloc] init];   
  self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"下拉刷新"];  
  // 绑定下拉刷新事件 
  [self.refreshControl addTarget:self action:@selector(refreshTableViewAction:) forControlEvents:UIControlEventValueChanged]; 
   // 下面这条必须有,不然会造成tableView页面上面多出一小片空白   
  self.tableView.tableHeaderView = [[UIView alloc] init];

实现下拉刷新方法
-(void)refreshTableViewAction:(id)sender{
    AllListManager *allList = [[AllListManager alloc] init];
    [allList requestAllDataWithListId:self.author];
    allList.result = ^(NSMutableArray *resultArray){
        self.allDataArray = resultArray;
        [self.tableView reloadData];
  // 数据请求完成后 停止刷新。
  [self.refreshControl endRefreshing];
    };
    
}


猜你喜欢

转载自blog.csdn.net/liuya000/article/details/48296085