UIRefreshControl是tableViewController自带的.
在storyBoard中选中控制器,右边把Refreshing改成Enabled//设置refreshControl的显示内容
self.refreshControl.tintColor = [UIColor blueColor];//小菊花的颜色
self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"正在拼命加载..."attributes:@{NSForegroundColorAttributeName:[UIColorredColor]}];//设置标题文字和颜色
[self.refreshControl beginRefreshing];//开始刷新,
[self.refreshControl endRefreshing];//结束刷新
=========================================
// UITableView *tab=[[UITableViewalloc]initWithFrame:self.view.framestyle:UITableViewStylePlain];
// UIRefreshControl *r=[[UIRefreshControl alloc]init];
// tab.refreshControl=r;//系统自带的刷新控件
自己创建UIRefreshControl
self.refreshControl = [[UIRefreshControlalloc]init];
[self.tbaddSubview:self.refreshControl];//可以不加这句话,系统自动管理UIRefreshControl,自动添加到tableview视图中;
[selfsetRefreshControl:self.refreshControl];//tableviewcontroller控制器设置刷新控件 ,可以不设置
self.refreshControl.attributedTitle = [[NSAttributedStringalloc]initWithString:@"努力加载中……"];
self.refreshControl.tintColor = [UIColorgrayColor];
[self.refreshControladdTarget:selfaction:@selector(refreshAction)forControlEvents:UIControlEventValueChanged];
- (void)refreshAction{
}
===============================
自定义上拉刷新和下拉刷新的原理:当tablebIew滚动到一个临界值时,执行响应的刷新数据的方法,改变状态文字和图标;
在swift中实现上啦静默加载
//小菊花
private lazyvar indicatorView:UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle:UIActivityIndicatorViewStyle.Gray)
//刷新提示的文案
private lazyvar tipLabel:UILabel = {
let l = UILabel(frame:CGRect(x:0, y:-64, width:KWidth, height:40))
l.textColor = UIColor.whiteColor()
l.font = UIFont.systemFontOfSize(17)
l.textAlignment = .Center
l.backgroundColor =themeColor
return l
}()
override func tableView(tableView:UITableView, numberOfRowsInSection section:Int) -> Int {
returnself.listViewModel.statuses.count
}
override func tableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell {
//手写代码必须手动注册cell
let cell = tableView.dequeueReusableCellWithIdentifier(HomeCellId, forIndexPath: indexPath)as!StatusCell
//显示文案
// cell.textLabel?.text = self.statuses[indexPath.row].user?.name
cell.status = self.listViewModel.statuses[indexPath.row]
//将要加载最后一个cell的时候并且小菊花没有转动的情况下
if indexPath.row ==self.listViewModel.statuses.count -2 && !indicatorView.isAnimating(){
//1.转动小菊花
indicatorView.startAnimating()
//开始加载数据加载更多数据
loadData()
print("开始静默加载数据")
}
return cell
}