0
点赞
收藏
分享

微信扫一扫

[IOS]Pull To Refresh 下拉刷新



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

 

方法一:使用第三方插件


@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];

}


#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];
}


 

举报

相关推荐

0 条评论