RankingTableViewController.swift
10.1 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//
// RankingTableViewController.swift
// YouerLiveVideo
//
// Created by 葛建军 on 17/5/20.
// Copyright © 2017年 左丞. All rights reserved.
//
import UIKit
class RankingTableViewController: UITableViewController {
var openIndexAry:[Int]=[0,4] //记录那些是展开状态
var allDic:[Int:[String]]=Dictionary<Int,[String]>()
var ary:[String]=["综合排名","资源贡献","下载排名","阅读排名","综合排名","资源贡献","下载排名","阅读排名"]
override func viewDidLoad() {
super.viewDidLoad()
getAllSubRankings()
}
func getAllSubRankings(){
for i in 0..<8{
allDic.updateValue([], forKey: i)
}
AppDelegate.instance().httpServer.getSchoolGeneral { (str, error) in
if error==nil {
if JSON.fromString(jsonString: str)!["status"].intValue == 1{
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
var lineAry:[String]=[]
for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
lineAry.append(item["f_SchoolName"].stringValue)
}
self.allDic.updateValue(lineAry, forKey: 0)
self.tableView.reloadData()
}, failHandler: { (error) in
})
}
}
}
AppDelegate.instance().httpServer.getSchoolUpload { (str, error) in
if error==nil {
if JSON.fromString(jsonString: str)!["status"].intValue == 1{
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
var lineAry:[String]=[]
for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
lineAry.append(item["f_SchoolName"].stringValue)
}
self.allDic.updateValue(lineAry, forKey: 1)
self.tableView.reloadData()
}, failHandler: { (error) in
})
}
}
}
AppDelegate.instance().httpServer.getSchoolDownloads { (str, error) in
if error==nil {
if JSON.fromString(jsonString: str)!["status"].intValue == 1{
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
var lineAry:[String]=[]
for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
lineAry.append(item["f_SchoolName"].stringValue)
}
self.allDic.updateValue(lineAry, forKey: 2)
self.tableView.reloadData()
}, failHandler: { (error) in
})
}
}
}
AppDelegate.instance().httpServer.getSchoolPv { (str, error) in
if error==nil {
if JSON.fromString(jsonString: str)!["status"].intValue == 1{
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
var lineAry:[String]=[]
for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
lineAry.append(item["f_SchoolName"].stringValue)
}
self.allDic.updateValue(lineAry, forKey: 3)
self.tableView.reloadData()
}, failHandler: { (error) in
})
}
}
}
AppDelegate.instance().httpServer.getTeacherGenerals { (str, error) in
if error==nil {
if JSON.fromString(jsonString: str)!["status"].intValue == 1{
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
var lineAry:[String]=[]
for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
lineAry.append(item["f_SchoolName"].stringValue)
}
self.allDic.updateValue(lineAry, forKey: 4)
self.tableView.reloadData()
}, failHandler: { (error) in
})
}
}
}
AppDelegate.instance().httpServer.getTeacherUpload { (str, error) in
if error==nil {
if JSON.fromString(jsonString: str)!["status"].intValue == 1{
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
var lineAry:[String]=[]
for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
lineAry.append(item["f_SchoolName"].stringValue)
}
self.allDic.updateValue(lineAry, forKey: 5)
self.tableView.reloadData()
}, failHandler: { (error) in
})
}
}
}
AppDelegate.instance().httpServer.getTeacherDownload { (str, error) in
if error==nil {
if JSON.fromString(jsonString: str)!["status"].intValue == 1{
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
var lineAry:[String]=[]
for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
lineAry.append(item["f_SchoolName"].stringValue)
}
self.allDic.updateValue(lineAry, forKey: 6)
self.tableView.reloadData()
}, failHandler: { (error) in
})
}
}
}
AppDelegate.instance().httpServer.getTeacherPvs { (str, error) in
if error==nil {
if JSON.fromString(jsonString: str)!["status"].intValue == 1{
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
var lineAry:[String]=[]
for item in JSON.fromString(jsonString: str)!["data"].arrayValue {
lineAry.append(item["f_SchoolName"].stringValue)
}
self.allDic.updateValue(lineAry, forKey: 7)
self.tableView.reloadData()
}, failHandler: { (error) in
})
}
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 8
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
var height:CGFloat=44
if indexPath.row==0 || indexPath.row==4{
height=height+44
}
if indexPath.row != 3{
height=height+20
}
if openIndexAry.contains(indexPath.row){
height=height+CGFloat(30*allDic[indexPath.row]!.count)
}
return height
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell=tableView.dequeueReusableCell(withIdentifier: "ItemTableViewCell", for: indexPath) as! ItemTableViewCell
cell.superVC=self
cell.indexPath=indexPath
if indexPath.row==0{
cell.sectionTitleLabel.text="学校排行"
cell.sectionTitleLabel.isHidden=false
}
if indexPath.row==4{
cell.sectionTitleLabel.text="教师排行"
cell.sectionTitleLabel.isHidden=false
}
if indexPath.row==0 || indexPath.row==4{
cell.titleViewTop.constant=44
}else{
cell.titleViewTop.constant=0
}
if indexPath.row==3{
cell.tableViewButtom.constant=0
}else{
cell.tableViewButtom.constant=20
}
cell.titleLabel.text=ary[indexPath.row]
if openIndexAry.contains(indexPath.row){
cell.titleImageView.image=UIImage(named: "icon_open")
}else{
cell.titleImageView.image=UIImage(named: "icon_more")
}
cell.subTableView.reloadData()
return cell
}
}
class ItemTableViewCell: UITableViewCell,UITableViewDelegate,UITableViewDataSource {
var superVC:RankingTableViewController?
var indexPath:IndexPath!
@IBOutlet var sectionTitleLabel: UILabel!
@IBOutlet var titleViewTop: NSLayoutConstraint!
@IBOutlet var subTableView: UITableView!
@IBOutlet var tableViewButtom: NSLayoutConstraint!
@IBOutlet var titleLabel: UILabel!
@IBOutlet var titleImageView: UIImageView!
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if superVC != nil {
if superVC!.openIndexAry.contains(indexPath.row){
return superVC!.allDic[indexPath.row]!.count
}else{
return 0
}
}else{
return 0
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 30
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell=tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
if superVC != nil {
cell.textLabel?.text="\(superVC!.allDic[self.indexPath.row]![indexPath.row])"
}
return cell
}
@IBAction func openOrCloseAction(_ sender: UIButton) {
if superVC!.openIndexAry.contains(indexPath.row){
superVC!.openIndexAry.remove(at: getCurrentIndex(item: indexPath.row, arry: superVC!.openIndexAry))
}else{
superVC!.openIndexAry.append(indexPath.row)
}
superVC!.tableView.reloadData()
}
}