HistoryViewController.swift 4.05 KB
//
//  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"))
        }
    }
}