参考: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];
}
本文介绍了两种实现 iOS 下拉刷新的方法:一是通过 SSARefreshControl 第三方插件;二是使用 UIRefreshControl。文中提供了详细的代码示例,展示了如何配置刷新控件、加载数据以及结束刷新过程。
1002

被折叠的 条评论
为什么被折叠?



