IHAreaListView.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // IHAreaListView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2019/12/13.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. protocol IHAreaListViewDelegate : NSObjectProtocol {
  10. func areaListViewDidSelectRowAt(indexPath: IndexPath)
  11. }
  12. class IHAreaListView: UIView {
  13. var roomList : [RoomData]? {
  14. didSet{
  15. self.tableView.reloadData()
  16. }
  17. }
  18. weak var listDelegate : IHAreaListViewDelegate?
  19. lazy var tableView: UITableView = {
  20. let tableView = UITableView(frame: CGRect.zero, style: .plain)
  21. tableView.delegate = self
  22. tableView.dataSource = self
  23. tableView.backgroundColor = UIColor(hexString: "#F6F8F7")
  24. tableView.separatorStyle = .none
  25. //tableView.register(UINib(nibName: "IHAreaListCell", bundle: nil), forCellReuseIdentifier: "cell")
  26. return tableView
  27. }()
  28. override init(frame: CGRect) {
  29. super.init(frame: frame)
  30. addSubview(tableView)
  31. }
  32. override func layoutSubviews() {
  33. super.layoutSubviews()
  34. self.tableView.frame = self.bounds
  35. // self.tableView.frame = CGRect.init(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT)
  36. }
  37. required init?(coder: NSCoder) {
  38. fatalError("init(coder:) has not been implemented")
  39. }
  40. }
  41. extension IHAreaListView:UITableViewDataSource,UITableViewDelegate{
  42. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  43. return self.roomList?.count ?? 0
  44. }
  45. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  46. // let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! IHAreaListCell
  47. // cell.selectionStyle = .none
  48. // let room = self.roomList![indexPath.row]
  49. // cell.room = room
  50. // return cell
  51. let room = self.roomList![indexPath.row]
  52. var cell : IHAreaListCell?
  53. if room.type == "1"{
  54. //学校
  55. cell = tableView.dequeueReusableCell(withIdentifier: "ClassRoom") as? IHAreaListCell
  56. if cell == nil{
  57. cell = Bundle.main.loadNibNamed("IHAreaListCell", owner: nil, options: nil)?.last as? IHAreaListCell
  58. cell!.selectionStyle = .none
  59. }
  60. }else{
  61. //酒店
  62. cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? IHAreaListCell
  63. if cell == nil{
  64. cell = Bundle.main.loadNibNamed("IHAreaListCell", owner: nil, options: nil)?.first as? IHAreaListCell
  65. cell!.selectionStyle = .none
  66. }
  67. }
  68. cell!.room = room
  69. return cell!
  70. }
  71. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  72. return 150
  73. }
  74. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  75. if let delegate = listDelegate {
  76. delegate.areaListViewDidSelectRowAt(indexPath: indexPath)
  77. }
  78. }
  79. }