-
Notifications
You must be signed in to change notification settings - Fork 114
Expand file tree
/
Copy pathRefreshController.swift
More file actions
130 lines (106 loc) · 4.09 KB
/
RefreshController.swift
File metadata and controls
130 lines (106 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// RefreshController.swift
// CRRefresh
//
// **************************************************
// * _____ *
// * __ _ __ ___ \ / *
// * \ \/ \/ / / __\ / / *
// * \ _ / | (__ / / *
// * \/ \/ \___/ / /__ *
// * /_____/ *
// * *
// **************************************************
// Github :https://github.com/imwcl
// HomePage:http://imwcl.com
// CSDN :http://blog.csdn.net/wang631106979
//
// Created by 王崇磊 on 16/9/14.
// Copyright © 2016年 王崇磊. All rights reserved.
//
// @class RefreshController
// @abstract 刷新VC
// @discussion 刷新VC
//
import UIKit
import CRRefresh
class RefreshController: BaseViewController {
var tableView: UITableView = {
let table = UITableView(frame: .zero, style: .grouped)
return table
}()
var count: Int = 10
var refresh: Refresh
init(refresh: Refresh) {
self.refresh = refresh
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//MARK: Public Methods
override func configNavBar() {
super.configNavBar()
addNavDefaultBackButton()
navTitle = refresh.model.title
}
override func configView() {
super.configView()
tableView.frame = .init(x: 0, y: 0, width: view.frame.width, height: view.frame.height - 64)
tableView.register(UINib.init(nibName: "RefreshCell", bundle: nil), forCellReuseIdentifier: "RefreshCell")
view.addSubview(tableView)
tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = .none
tableView.cr.addHeadRefresh(animator: refresh.header.commont()) { [weak self] in
print("开始刷新")
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
self?.count = 10
self?.tableView.cr.endHeaderRefresh()
self?.tableView.cr.resetNoMore()
self?.tableView.reloadData()
})
}
tableView.cr.beginHeaderRefresh()
tableView.cr.addFootRefresh(animator: refresh.footer.commont()) { [weak self] in
print("开始加载")
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
self?.count += 10
self?.tableView.cr.endLoadingMore()
self?.tableView.reloadData()
})
}
tableView.isPagingEnabled = true
}
//MARK: Override
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
// MARK: - Table view data source
extension RefreshController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return count
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 130
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "RefreshCell", for: indexPath) as! RefreshCell
return cell
}
}