iOS TableView实现下拉刷新数据

1. 创建刷新控件, 可通过xib或代码方式创建控件:

- (void)setupDownRefresh
{
    /* 添加刷新控件 */
    UIRefreshControl *control = [[UIRefreshControl alloc] init];
    
    // 监听事件
    [control addTarget:self action:@selector(loadNewDatas:) forControlEvents:UIControlEventValueChanged];
    
    [self.tableView addSubview:control];
    
/* 进入界面先刷新一次数据 */
// 进入刷新状态 [control beginRefreshing]; // 刷新数据 [self loadNewDatas:control]; }

2. 将新数据加载到原数据的前面:

// 插入数据前面
[self.data insertObject:kNewData atIndex:0];

3. 刷新表格并结束刷新状态:

// 刷新TableView
[self.tableView reloadData];
        
// 结束刷新状态
[control endRefreshing];

Demo:https://github.com/BigPlane/DownRefreshDemo

原文地址:https://www.cnblogs.com/happyplane/p/4724413.html