IHSensorView.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // IHSensorView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/17.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. class IHSensorView: UIView {
  10. var sensorData:SensorInfodata?{
  11. didSet{
  12. self.tableView.reloadData()
  13. }
  14. }
  15. lazy var tableView: UITableView = {
  16. let tableView = UITableView(frame: CGRect.zero, style: .plain)
  17. tableView.delegate = self
  18. tableView.dataSource = self
  19. tableView.separatorStyle = .none
  20. tableView.register(UINib(nibName: "IHSensorFirstCell", bundle: nil), forCellReuseIdentifier: "firstcell")
  21. // tableView.register(UINib(nibName: "IHSensorDeviceCell", bundle: nil), forCellReuseIdentifier: "devicecell")
  22. tableView.register(UINib(nibName: "IHSensorDeviceCell2", bundle: nil), forCellReuseIdentifier: "devicecell")
  23. return tableView
  24. }()
  25. override init(frame: CGRect) {
  26. super.init(frame: frame)
  27. backgroundColor = .white
  28. addSubview(tableView)
  29. }
  30. required init?(coder: NSCoder) {
  31. fatalError("init(coder:) has not been implemented")
  32. }
  33. override func layoutSubviews() {
  34. super.layoutSubviews()
  35. tableView.frame = self.bounds
  36. }
  37. }
  38. extension IHSensorView: UITableViewDelegate,UITableViewDataSource {
  39. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  40. return 2
  41. }
  42. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  43. if indexPath.row == 0 {
  44. let cell = tableView.dequeueReusableCell(withIdentifier: "firstcell") as! IHSensorFirstCell
  45. cell.sensorData = self.sensorData
  46. cell.selectionStyle = .none
  47. return cell
  48. }else{
  49. // let cell = tableView.dequeueReusableCell(withIdentifier: "devicecell") as! IHSensorDeviceCell
  50. // cell.sensorData = self.sensorData
  51. // cell.selectionStyle = .none
  52. // return cell
  53. let cell = tableView.dequeueReusableCell(withIdentifier: "devicecell") as! IHSensorDeviceCell2
  54. cell.sensorData = self.sensorData
  55. cell.selectionStyle = .none
  56. return cell
  57. }
  58. }
  59. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  60. if indexPath.row == 0 {
  61. let alarmStatus = self.sensorData?.alarmStatus
  62. return alarmStatus == "1" ? (450 - 61) : (450 - 60 - 61)
  63. }else{
  64. return 450
  65. }
  66. }
  67. }