1. 创建
lazy var tableView : UITableView = {
lettableView =UITableView.init(frame:.zero,style:UITableView.Style.plain)
tableView.separatorStyle = UITableViewCell.SeparatorStyle.singleLine
tableView.backgroundColor="F3F6F9".uicolor()
tableView.separatorInset=UIEdgeInsets.init(top:0,left:0,bottom:0,right:0)
tableView.estimatedRowHeight=0
tableView.estimatedSectionFooterHeight = 0
tableView.estimatedSectionHeaderHeight = 0
tableView.dataSource=self
tableView.delegate=self
tableView.register(MyCell.self, forCellReuseIdentifier: "mycell")
tableView.tableFooterView=UIView()
// 下拉刷新
tableView.es.addPullToRefresh(animator: header, handler: {
[unownedself]in
self.headerRereshing()
});
// 上拉加载
tableView.es.addInfiniteScrolling(animator: footer) {
[unownedself]in
self.footerRereshing()
}
returntableView
}()
2.事件
/// 下拉刷新
func headerRereshing() {
UIView .performWithoutAnimation {
self.tableView.es.stopPullToRefresh()
}
}
///上拉加载
func footerRereshing() {
UIView.performWithoutAnimation {
self.tableView.es.stopLoadingMore()
}
}
extension ViewController: UITableViewDelegate,UITableViewDataSource {
functableView(_tableView:UITableView,numberOfRowsInSectionsection:Int) ->Int{
return 8
}
functableView(_tableView:UITableView,cellForRowAtindexPath:IndexPath) ->UITableViewCell{
let cell:MyTableViewCell! = tableView.dequeueReusableCell(withIdentifier: "mycell",for: indexPath) as?MyTableViewCell
returncell
}
functableView(_tableView:UITableView,heightForRowAtindexPath:IndexPath) ->CGFloat{
return156.0
}
}
class MyTableViewCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: .default,reuseIdentifier: reuseIdentifier)
self.selectionStyle = UITableViewCell.SelectionStyle.none
}
requiredinit?(coder:NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}