MJRefresh - github
@[toc]
1.判断是上拉还是下拉
var isPullDown = true
if refreshHeader.isRefreshing {
isPullDown = true
} else {
isPullDown = false
}
2.没有更多数据了
refreshFooter.endRefreshingWithNoMoreData()
- 取消显示没有更多数据了
refreshFooter.resetNoMoreData()
3.隐藏MJRefreshHeader
4.完整代码
lazy var refreshHeader: MJRefreshNormalHeader = MJRefreshNormalHeader(refreshingTarget: self, refreshingAction: #selector(loadData))
lazy var refreshFooter: MJRefreshAutoNormalFooter = MJRefreshAutoNormalFooter(refreshingTarget: self, refreshingAction: #selector(loadData))
tableView.mj_header = self.refreshHeader
tableView.mj_footer = self.refreshFooter
var isPullDown = true
var currentPage = 1
var lastPage = 100
var modelArr:[FDMomentModel] = []
override func loadData(){
printXY(#function, obj: self, line: #line)
guard currentPage < lastPage || refreshHeader.isRefreshing == true else {
refreshFooter.endRefreshingWithNoMoreData()
return
}
if refreshHeader.isRefreshing == true {
currentPage = 1
isPullDown = true
modelArr = []
lastPage = 100
refreshFooter.resetNoMoreData()
}else{
currentPage += 1
isPullDown = false
}
getLikesMoment()
}
//获取精选动态
func getLikesMoment(){
weak var weakSelf = self
SSNetworkManager.shared.getThemeData(type: .likes,page:currentPage) { (commonModel) in
if weakSelf != nil{
if weakSelf!.isPullDown {
weakSelf?.refreshHeader.endRefreshing()
}else{
weakSelf?.refreshFooter.endRefreshing()
}
}
if commonModel.error == nil{
if commonModel.code == 0 {
let dict:NSDictionary = commonModel.data as! NSDictionary
let nsarr:NSArray = dict["data"] as! NSArray
if let modelArray = [FDMomentModel].deserialize(from: nsarr) {
let arr = modelArray as! [FDMomentModel]
weakSelf?.modelArr += arr
weakSelf?.tableView.reloadData()
}
weakSelf?.lastPage = dict["last_page"] as! Int