// // IHSensorView.swift // Inhealth // // Created by weclouds on 2019/12/17. // Copyright © 2019 weclouds. All rights reserved. // import UIKit class IHSensorView: UIView { var sensorData:SensorInfodata?{ didSet{ self.tableView.reloadData() } } lazy var tableView: UITableView = { let tableView = UITableView(frame: CGRect.zero, style: .plain) tableView.delegate = self tableView.dataSource = self tableView.separatorStyle = .none tableView.register(UINib(nibName: "IHSensorFirstCell", bundle: nil), forCellReuseIdentifier: "firstcell") // tableView.register(UINib(nibName: "IHSensorDeviceCell", bundle: nil), forCellReuseIdentifier: "devicecell") tableView.register(UINib(nibName: "IHSensorDeviceCell2", bundle: nil), forCellReuseIdentifier: "devicecell") return tableView }() override init(frame: CGRect) { super.init(frame: frame) backgroundColor = .white addSubview(tableView) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func layoutSubviews() { super.layoutSubviews() tableView.frame = self.bounds } } extension IHSensorView: UITableViewDelegate,UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 2 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 0 { let cell = tableView.dequeueReusableCell(withIdentifier: "firstcell") as! IHSensorFirstCell cell.sensorData = self.sensorData cell.selectionStyle = .none return cell }else{ // let cell = tableView.dequeueReusableCell(withIdentifier: "devicecell") as! IHSensorDeviceCell // cell.sensorData = self.sensorData // cell.selectionStyle = .none // return cell let cell = tableView.dequeueReusableCell(withIdentifier: "devicecell") as! IHSensorDeviceCell2 cell.sensorData = self.sensorData cell.selectionStyle = .none return cell } } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { if indexPath.row == 0 { let alarmStatus = self.sensorData?.alarmStatus return alarmStatus == "1" ? (450 - 61) : (450 - 60 - 61) }else{ return 450 } } }