[IOS]Pull To Refresh 下拉刷新

丁经略
2023-12-01

参考:http://www.oschina.net/p/ssapulltorefresh

github: https://github.com/SSA111/SSAPullToRefresh

 

方法一:使用第三方插件

1.

@interface DevicesListController()<SSARefreshControlDelegate>

-(void)viewDidLoad{
    
    [self initData];
    
    
    _refreshControl = [[SSARefreshControl alloc] initWithScrollView:_deviceListTableView andRefreshViewLayerType:SSARefreshViewLayerTypeOnScrollView];
    _refreshControl.delegate = self;
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_deviceListTableView];
    
}

 

2.

#pragma mark - pull to refresh
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    [self.refreshControl beginRefreshing];
    
}

- (void)beganRefreshing {
    
    [self loadDataSource];
    
}

- (void)loadDataSource {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        sleep(1.5);
        dispatch_async(dispatch_get_main_queue(), ^{
            //refresh data resource
            [self deviceCounts];
            [self searchDeviceList];
[_deviceListTableView reloadData];
            [self.refreshControl endRefreshing];
        });
        
    });
}

 

方法二:使用UIRefreshControl

1.创建

@property (strong, nonatomic) UIRefreshControl *refresh;

-(void)configFulllRefresh{
    _refresh = [[UIRefreshControl alloc]initWithFrame:CGRectZero];
    [_device_list_tableView addSubview:_refresh];
    [_refresh addTarget:self action:@selector(loadData) forControlEvents:UIControlEventValueChanged];
}

 

2.下拉时触发

-(void)loadData{
    
    [self searchDeviceList];
    NSLog(@"load data");
}

 

3.任务接触时可以调用

-(void)endLoad{
    NSLog(@"End Refresh");
    [_refresh endRefreshing];
}

 

 类似资料: