123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- //
- // IHAirQualityView.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/12.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import UIKit
- import JXPagingView
- import TKSwitcherCollection
- let kNotificationIHAirQualityViewReloadAirData = "kNotificationIHAirQualityViewReloadAirData"
- class IHAirQualityView: UIView ,UIScrollViewDelegate{
- //环境信息
- var envorenmentInfo : Home_room_env_status?{
- didSet{
- if self.envorenmentInfo != nil {
- self.tableView.reloadData()
- }
- }
- }
- static let switchCellId = "switchCellId"
- static let levelCellId = "levelCellId"
- static let subHeaderCellId = "subHeaderCellId"
- static let normalCellId = "normalCellId"
- static let weeklyCellId = "weeklyCellId"
- static let chartsCellId = "chartsCellId" //
- lazy var tableView: UITableView = {
- let tableView = UITableView(frame:self.bounds, style: .plain)
- tableView.dataSource = self
- tableView.delegate = self
- return tableView
- }()
-
-
- var listViewDidScrollCallback: ((UIScrollView) -> ())?
- override init(frame: CGRect) {
- super.init(frame: frame)
- addSubview(tableView)
- self.backgroundColor = UIColor.white
- self.tableView.backgroundColor = UIColor.white
- tableView.separatorStyle = .none
-
- tableView.register(UINib(nibName: "IHAQSwitchCell", bundle: nil), forCellReuseIdentifier: IHAirQualityView.switchCellId)
- tableView.register(UINib(nibName: "IHAQLevelCell", bundle: nil), forCellReuseIdentifier: IHAirQualityView.levelCellId)
- tableView.register(UINib(nibName: "IHAQSubHeaderCell", bundle: nil), forCellReuseIdentifier: IHAirQualityView.subHeaderCellId)
- tableView.register(UINib(nibName: "IHAQNormalCell", bundle: nil), forCellReuseIdentifier: IHAirQualityView.normalCellId)
- tableView.register(UINib(nibName: "IHWeeklyCell", bundle: nil), forCellReuseIdentifier: IHAirQualityView.weeklyCellId)
- tableView.register(UINib(nibName: "IHQualityChartsCell", bundle: nil), forCellReuseIdentifier: IHAirQualityView.chartsCellId)
-
-
- NotificationCenter.default.addObserver(self, selector: #selector(reloadAirData(_:)), name: NSNotification.Name(kNotificationIHAirQualityViewReloadAirData), object: nil)
- }
-
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- @objc func reloadAirData(_ notify:Notification) {
- let result = notify.object as! Home_room_env_status
- self.envorenmentInfo = result
- }
- override func layoutSubviews() {
- super.layoutSubviews()
- tableView.frame = self.bounds
- }
- func scrollViewDidScroll(_ scrollView: UIScrollView) {
- self.listViewDidScrollCallback?(scrollView)
- }
- }
- extension IHAirQualityView:UITableViewDelegate,UITableViewDataSource{
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return 4
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- if indexPath.row == 0{
- let cell = tableView.dequeueReusableCell(withIdentifier: IHAirQualityView.levelCellId) as! IHAQLevelCell
- cell.selectionStyle = .none
- return cell
- }else if indexPath.row == 1 {
- let cell = tableView.dequeueReusableCell(withIdentifier: IHAirQualityView.subHeaderCellId) as! IHAQSubHeaderCell
- cell.selectionStyle = .none
- return cell
- }else if indexPath.row == 2{
- let cell = tableView.dequeueReusableCell(withIdentifier: IHAirQualityView.chartsCellId) as! IHQualityChartsCell
- cell.averageAir = self.envorenmentInfo?.averageAir
- cell.dataList = self.envorenmentInfo?.dataList
- cell.timeList = self.envorenmentInfo?.timeList
- cell.selectionStyle = .none
- return cell
- }else {
- let cell = tableView.dequeueReusableCell(withIdentifier: IHAirQualityView.weeklyCellId) as! IHWeeklyCell
- cell.selectionStyle = .none
- cell.humidity = self.envorenmentInfo?.humidity
- cell.temperature = self.envorenmentInfo?.temperature
- return cell
- }
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- if indexPath.row == 0{
- return 100
- }else if indexPath.row == 1 {
- return 50
- }else if indexPath.row == 2{
- return 147
- }else {
- return 134
- }
- }
- }
- extension IHAirQualityView:JXPagingViewListViewDelegate{
- func listView() -> UIView {
- return self
- }
-
- func listScrollView() -> UIScrollView {
- return self.tableView
- }
-
- func listViewDidScrollCallback(callback: @escaping (UIScrollView) -> ()) {
- self.listViewDidScrollCallback = callback
- }
-
-
- }
|