MoreTVStationViewController.swift
6.82 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
//
// MoreTVStationViewController.swift
// YouerLiveVideo
//
// Created by 左丞 on 2017/5/16.
// Copyright © 2017年 左丞. All rights reserved.
//
import UIKit
class MoreTVStationViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
var topTenTVStation:[TVStationInfor] = []
var xxcellentSchool:[TVStationInfor] = []
var excellentTVStationProgram:[TVStationSubject] = []
var type:Int = 0 //0:十佳电视台,1:优秀电视台,2:优秀校园节目
var pageIndex:Int = 2
override func viewDidLoad() {
super.viewDidLoad()
self.automaticallyAdjustsScrollViewInsets = false
if type != 0{
addCellAndRefresh()
}
// Do any additional setup after loading the view.
}
func addCellAndRefresh(){
collectionView.mj_header=MJRefreshNormalHeader(refreshingTarget: self, refreshingAction: #selector(MoreTVStationViewController.loadNewData))
collectionView.mj_footer=MJRefreshAutoNormalFooter(refreshingTarget: self, refreshingAction: #selector(MoreTVStationViewController.loadMoreData))
}
// MARK: - 下拉刷新
func loadNewData(){
pageIndex=1
getTVStation() { (finish) in
self.collectionView.mj_header.endRefreshing()
}
}
// MARK: - 上拉加载更多
func loadMoreData(){
getTVStation() { (finish) in
self.collectionView.mj_footer.endRefreshing()
}
}
func getTVStation(finish: @escaping (Bool)->()){
if type == 1{
AppDelegate.instance().httpServer.postExcellentSchool(parameters: ["pageIndex":pageIndex as AnyObject,"pageSize":8 as AnyObject]) { (str, error) in
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
if json.contentData().dictionaryValue["resultData"] != nil{
if self.pageIndex==1{
self.xxcellentSchool.removeAll()
}
for item in json.contentData().dictionaryValue["resultData"]!.arrayValue{
self.xxcellentSchool.append(TVStationInfor(json: item))
}
if json.contentData().dictionaryValue["resultData"]!.arrayValue.count > 0{
self.pageIndex=self.pageIndex+1
}
finish(true)
self.collectionView.reloadData()
}
}, failHandler: { (error) in
finish(false)
})
}
}else if type == 2{
AppDelegate.instance().httpServer.postExcellentProgram(parameters: ["pageIndex":pageIndex as AnyObject,"pageSize":8 as AnyObject]) { (str, error) in
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
if json.contentData().dictionaryValue["resultData"] != nil{
if self.pageIndex==1{
self.excellentTVStationProgram.removeAll()
}
for item in json.contentData().dictionaryValue["resultData"]!.arrayValue{
self.excellentTVStationProgram.append(TVStationSubject(json: item))
}
if json.contentData().dictionaryValue["resultData"]!.arrayValue.count > 0{
self.pageIndex=self.pageIndex+1
}
finish(true)
self.collectionView.reloadData()
}
}, failHandler: { (error) in
finish(false)
})
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// 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 MoreTVStationViewController:UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if type == 2{
let vc = Story.instantiateViewControllerWithIdentifier("TVStationInforViewControllerVC", storyName: "TVStation") as! TVStationInforViewController
vc.excellentTVStationProgram = excellentTVStationProgram[indexPath.row]
self.navigationController?.pushViewController(vc, animated: true)
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MoreTVStationViewCollectionCell
if type == 0{
cell.tvPicture.sd_setImage(with: URL(string: topTenTVStation[indexPath.row].f_Logo), placeholderImage: UIImage(named:"icon"))
cell.tvStationName.text = topTenTVStation[indexPath.row].f_SchoolName
}else if type == 1{
cell.tvPicture.sd_setImage(with: URL(string: xxcellentSchool[indexPath.row].f_Logo), placeholderImage: UIImage(named:"icon"))
cell.tvStationName.text = xxcellentSchool[indexPath.row].f_SchoolName
}else if type == 2{
cell.tvPicture.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 type {
case 0:
return topTenTVStation.count
case 1:
return xxcellentSchool.count
case 2:
return excellentTVStationProgram.count
default:
return 0
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsetsMake(10, 10, 10, 10)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: (getScreenWidth()-30)/2, height: 180)
}
}
class MoreTVStationViewCollectionCell:UICollectionViewCell{
@IBOutlet weak var tvStationName: UILabel!
@IBOutlet weak var tvPicture: UIImageView!
}