ios的refreshControl控件

况谦
2023-12-01

1.TableViewController下使用

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //刷新
    self.refreshControl=[[UIRefreshControl alloc]initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 100)];
    [self.tableView.tableHeaderView addSubview:self.refreshControl];
    [self.refreshControl addTarget:self  action:@selector(loadData:) forControlEvents:UIControlEventValueChanged];
    

}
#pragma mark -loadData
-(void)loadData:(UIRefreshControl*)sender
{
    //加载数据,添加
    //[self.myDealTableView reloadData];
    [self getInformation];

    //结束刷新
    [self.refreshControl endRefreshing];
}

2.ViewController下使用

@property (strong,nonatomic)UIRefreshControl *refreshControl;
- (void)viewDidLoad {
    [super viewDidLoad];
    
    //刷新
self.refreshControl = [[UIRefreshControl alloc]initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 100)];
self.refreshControl.tintColor = [UIColor redColor];
[self.tableView addSubview:self.refreshControl];
[self.refreshControl addTarget:self action:@selector(load:) forControlEvents:UIControlEventValueChanged];
}
#pragma mark-load
-(void)load:(UIRefreshControl*)sender
{
    //开始刷新加载数据
    NSString *room = [NSString stringWithFormat:@"room-%d",arc4random_uniform(10)];
    [self.arrayM addObject:room];
    [self.tableView reloadData];

    //结束刷新
    [self.refreshControl endRefreshing];
}

资源参考
https://www.cnblogs.com/XYQ-208910/p/4839111.html

 类似资料: