HistoryViewController.swift
4.05 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
//
// HistoryViewController.swift
// YouerLiveVideo
//
// Created by 左丞 on 2017/5/23.
// Copyright © 2017年 左丞. All rights reserved.
//
import UIKit
class HistoryViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
var datatSet:[TVStationSubject] = []
var type:Int = 0// 资源类型 0-微课 1-资源
var isHistory:Int = 0
override func viewDidLoad() {
super.viewDidLoad()
if isHistory == 0{
AppDelegate.instance().httpServer.getHistroyView(parameters: ["f_ViewType":type as AnyObject,"pageIndex":1 as AnyObject]) { (str, error) in
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
for item in json.contentData()["resultData"].arrayValue{
self.datatSet.append(TVStationSubject(json: item))
}
self.collectionView.reloadData()
}, failHandler: { (error) in
})
}
}else{
AppDelegate.instance().httpServer.getHistroyView(parameters: ["f_ViewType":type as AnyObject,"pageIndex":1 as AnyObject]) { (str, error) in
httpJsonResule(jsonString: str, error: error, successHandler: { (json) in
for item in json.contentData()["resultData"].arrayValue{
self.datatSet.append(TVStationSubject(json: item))
}
self.collectionView.reloadData()
}, failHandler: { (error) in
})
}
}
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.isHidden = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.tabBarController?.hidesBottomBarWhenPushed = false
}
/*
// 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 HistoryViewController:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! TVStationClassCell
let item = datatSet[indexPath.row]
cell.model = item
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return datatSet.count
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: (getScreenWidth()-30)/2, height: 200)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsetsMake(10, 10, 10, 10)
}
}
class TVStationClassCell: UICollectionViewCell {
@IBOutlet weak var name: UILabel!
@IBOutlet weak var photo: UIImageView!
var model:TVStationSubject?{
didSet{
name.text = model!.f_Title
photo.sd_setImage(with: URL(string:model!.f_Img), placeholderImage: #imageLiteral(resourceName: "placeholder"))
}
}
}