TVStationViewController.swift
13.5 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
//
// TVStationViewController.swift
// YouerLiveVideo
//
// Created by 左丞 on 2017/5/15.
// Copyright © 2017年 左丞. All rights reserved.
//
import UIKit
class TVStationViewController: UIViewController {
var dataSet:[AnyObject] = []
var topTenTVStation:[TVStationInfor] = []
var xxcellentSchool:[TVStationInfor] = []
var excellentTVStationProgram:[TVStationSubject] = []
@IBOutlet weak var tableView: UITableView!
var TVStationType:[String] = ["十佳电视台","优秀电视台","优秀校园节目"]
override func viewDidLoad() {
super.viewDidLoad()
self.configTheme()
getDataList()
self.automaticallyAdjustsScrollViewInsets = false
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(TVStationViewController.pushToSeachViewController))
// Do any additional setup after loading the view.
}
func pushToSeachViewController(){
let vc = Story.instantiateViewControllerWithIdentifier("SearchTVStationListViewControllerVC", storyName: "TVStation") as! SearchTVStationListViewController
vc.title = "搜索电视台"
self.navigationController?.pushViewController(vc, animated: true)
}
func getDataList(){
AppDelegate.instance().httpServer.getTopTenSchool(parameters: nil) { (str, error) in
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
for item in json.contentData().arrayValue{
self.topTenTVStation.append(TVStationInfor(json: item))
}
(self.tableView.cellForRow(at: IndexPath(item: 0, section: 0)) as? TVStationViewControllerTableViewCell)?.collectionView.reloadData()
}, failHandler: { (error) in
})
}
AppDelegate.instance().httpServer.postExcellentSchool(parameters: ["pageIndex":1 as AnyObject,"pageSize":8 as AnyObject]) { (str, error) in
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
if json.contentData().dictionaryValue["resultData"] != nil{
for item in json.contentData().dictionaryValue["resultData"]!.arrayValue{
self.xxcellentSchool.append(TVStationInfor(json: item))
}
(self.tableView.cellForRow(at: IndexPath(item: 0, section: 1)) as? TVStationViewControllerTableViewCell)?.collectionView.reloadData()
}
}, failHandler: { (error) in
})
}
AppDelegate.instance().httpServer.postExcellentProgram(parameters: ["pageIndex":1 as AnyObject,"pageSize":8 as AnyObject]) { (str, error) in
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
if json.contentData().dictionaryValue["resultData"] != nil{
for item in json.contentData().dictionaryValue["resultData"]!.arrayValue{
self.excellentTVStationProgram.append(TVStationSubject(json: item))
}
(self.tableView.cellForRow(at: IndexPath(item: 0, section: 2)) as? TVStationViewControllerTableViewCell)?.collectionView.reloadData()
}
}, failHandler: { (error) in
})
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func moreBtnClick(sender:UIButton){
let vc = Story.instantiateViewControllerWithIdentifier("MoreTVStationViewControllerVC", storyName: "TVStation") as! MoreTVStationViewController
switch sender.tag {
case 0:
vc.topTenTVStation = topTenTVStation
case 1:
vc.xxcellentSchool = xxcellentSchool
case 2:
vc.excellentTVStationProgram = excellentTVStationProgram
default:
break
}
vc.type = sender.tag
vc.title = TVStationType[sender.tag]
self.navigationController?.pushViewController(vc, animated: true)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
extension TVStationViewController:UITableViewDelegate,UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func numberOfSections(in tableView: UITableView) -> Int {
return TVStationType.count
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UIView(frame: CGRect(x: 0, y: 0, width: getScreenWidth(), height: 44))
view.backgroundColor = tableView.backgroundColor
let imageView = UIImageView(frame: CGRect(x: 8, y: 8, width: 28, height: 28))
imageView.image = UIImage(named: "icon")
let label = UILabel(frame: CGRect(x: imageView.frame.maxX+8, y: 11, width: 100, height: 21))
label.text = TVStationType[section]
label.textAlignment = .left
label.sizeToFit()
let btn = UIButton(frame: CGRect(x: getScreenWidth() - 8 - 30, y: 7, width: 30, height: 30))
btn.setImage(UIImage(named:"moreHot"), for: .normal)
btn.tag = section
btn.addTarget(self, action: #selector(TVStationViewController.moreBtnClick(sender:)), for: .touchUpInside)
view.addSubview(btn)
view.addSubview(label)
view.addSubview(imageView)
return view
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TVStationViewControllerTableViewCell
cell.collectionView.tag = indexPath.section+1
return cell
}
}
extension TVStationViewController:UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if collectionView.tag == 3{
let vc = Story.instantiateViewControllerWithIdentifier("ExcellentTVViewControllerVC", storyName: "TVStation") as! ExcellentTVViewController
self.navigationController?.pushViewController(vc, animated: true)
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! TVStationViewControllerCollectionCell
if collectionView.tag == 1{
cell.image.sd_setImage(with: URL(string: topTenTVStation[indexPath.row].f_Logo), placeholderImage: UIImage(named:"icon"))
cell.tvStationName.text = topTenTVStation[indexPath.row].f_SchoolName
}else if collectionView.tag == 2{
cell.image.sd_setImage(with: URL(string: xxcellentSchool[indexPath.row].f_Logo), placeholderImage: UIImage(named:"icon"))
cell.tvStationName.text = xxcellentSchool[indexPath.row].f_SchoolName
}else if collectionView.tag == 3{
cell.image.sd_setImage(with: URL(string: excellentTVStationProgram[indexPath.row].f_Img), placeholderImage: UIImage(named:"icon"))
cell.tvStationName.text = excellentTVStationProgram[indexPath.row].f_Title
}
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch collectionView.tag {
case 1:
return topTenTVStation.count
case 2:
return xxcellentSchool.count
case 3:
return excellentTVStationProgram.count
default:
return 0
}
}
}
class TVStationViewControllerTableViewCell:UITableViewCell{
@IBOutlet weak var collectionView: UICollectionView!
}
class TVStationViewControllerCollectionCell:UICollectionViewCell{
var index:Int!
@IBOutlet weak var image: UIImageView!
@IBOutlet weak var tvStationName: UILabel!
}
class TVStationInfor {
var f_SchoolType:String!
var f_Id:String! //标识字段,Guid标识 ,
var f_DeleteMark:Bool = false //删除标识,1-已删除 ,
var f_CreatorTime:String!//创建时间 ,
var f_CreatorUserId:String!//创建人员ID ,
var f_LastModifyTime:String! //最近一次编辑时间 ,
var f_LastModifyUserId:String! //最近一次编辑人员 ,
var f_DeleteTime:String! //删除时间 ,
var f_DeleteUserId:String! //删除人员 ,
var f_SchoolName:String! //学校名称 ,
var f_SchoolTypeId:String!// 学校类型 ,
var f_Logo:String! //校徽 ,
var f_IsTopTen:Bool = false //是否十佳校园电视台 ,
var f_IsExcellent:Bool = false //是否优秀校园电视台 ,
var f_Url:String!// 机构地址
init(json:JSON){
f_SchoolType = json["f_SchoolType"].stringValue
f_Id = json["f_Id"].stringValue
f_DeleteMark = json["f_DeleteMark"].boolValue
f_CreatorTime = json["f_CreatorTime"].stringValue
f_CreatorUserId = json["f_CreatorUserId"].stringValue
f_LastModifyTime = json["f_LastModifyTime"].stringValue
f_LastModifyUserId = json["f_LastModifyUserId"].stringValue
f_DeleteTime = json["f_DeleteTime"].stringValue
f_DeleteUserId = json["f_DeleteUserId"].stringValue
f_SchoolName = json["f_SchoolName"].stringValue
f_SchoolTypeId = json["f_SchoolTypeId"].stringValue
f_Logo = json["f_Logo"].stringValue
f_IsTopTen = json["f_IsTopTen"].boolValue
f_IsExcellent = json["f_IsExcellent"].boolValue
f_Url = json["f_Url"].stringValue
}
}
class TVStationSubject {
var f_Url:String!// 机构地址
var f_WaveTitle:String!
var f_ChapterName:String!
var f_TopicName:String!
var f_TestName:String!
var f_Id:String!// 标识字段,Guid标识 ,
var f_DeleteMark:Bool = false // 删除标识,1-已删除 ,
var f_CreatorTime:String!// 创建时间 ,
var f_CreatorUserId:String!// 创建人员ID ,
var f_LastModifyTime:String!// 最近一次编辑时间 ,
var f_LastModifyUserId:String!//最近一次编辑人员 ,
var f_DeleteTime:String!//删除时间 ,
var f_DeleteUserId:String!// 删除人员 ,
var f_Img :String!//课件图标/微课封面 ,
var f_Title:String!//课件名称 ,
var f_CreatorName:String!// 上传人员昵称 ,
var f_Pv:Int!// 浏览量 ,
var f_DownloadSum:Int!// 下载量 ,
var f_LoveSum:Int!// 点赞量 ,
var f_Price:Int!// 价格 ,
var f_WaveId:String!// 所属教材ID ,
var f_ChapterId:String!// 所属章节 ,
var f_TopicId:String!//所属知识点 ,
var f_TestId:String!//所属考点 ,
var f_SchoolId:String!// 上传老师的学校ID ,
var f_IsExamine:Int!// 审核状态:0-未审核,1-审核通过,2-审核不通过 ,
var f_ExamineUserId :String!//审核人ID ,
var f_ExamineName:String!//审核人姓名 ,
var f_ExamineDatetime :String!// 审核日期 ,
var f_ResourceType:Int!// 资源类型 0-微课 1-资源 2-电视台 ,
var f_ResourceUrl:String!// 资源地址 ,
var f_IsOpen:Bool = false // 是否公开 ,
var f_Detail :String!// 资源简介 ,
var f_TelevisionId :String!//电视台目录
init(json:JSON){
f_Url = json["f_Url"].stringValue
f_WaveTitle = json["f_WaveTitle"].stringValue
f_ChapterName = json["f_ChapterName"].stringValue
f_TopicName = json["f_TopicName"].stringValue
f_TestName = json["f_TestName"].stringValue
f_Id = json["f_Id"].stringValue
f_DeleteMark = json["f_DeleteMark"].boolValue
f_CreatorTime = json["f_CreatorTime"].stringValue
f_CreatorUserId = json["f_CreatorUserId"].stringValue
f_LastModifyTime = json["f_LastModifyTime"].stringValue
f_LastModifyUserId = json["f_LastModifyUserId"].stringValue
f_DeleteTime = json["f_DeleteTime"].stringValue
f_DeleteUserId = json["f_DeleteUserId"].stringValue
f_Img = json["f_Img"].stringValue
f_Title = json["f_Title"].stringValue
f_CreatorName = json["f_CreatorName"].stringValue
f_Pv = json["f_Pv"].intValue
f_DownloadSum = json["f_DownloadSum"].intValue
f_LoveSum = json["f_LoveSum"].intValue
f_Price = json["f_Price"].intValue
f_WaveId = json["f_WaveId"].stringValue
f_ChapterId = json["f_ChapterId"].stringValue
f_TopicId = json["f_TopicId"].stringValue
f_TestId = json["f_TestId"].stringValue
f_SchoolId = json["f_SchoolId"].stringValue
f_IsExamine = json["f_IsExamine"].intValue
f_ExamineUserId = json["f_ExamineUserId"].stringValue
f_ExamineName = json["f_ExamineName"].stringValue
f_ExamineDatetime = json["f_ExamineDatetime"].stringValue
f_ResourceType = json["f_ResourceType"].intValue
f_ResourceUrl = json["f_ResourceUrl"].stringValue
f_IsOpen = json["f_IsOpen"].boolValue
f_Detail = json["f_Detail"].stringValue
f_TelevisionId = json["f_TelevisionId"].stringValue
}
}