IHMapResultView.swift 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // IHMapResultView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2020/5/22.
  6. // Copyright © 2020 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. let kNotifactionIHMapResultViewReloadData = "kNotifactionIHMapResultViewReloadData"
  10. class IHMapResultView: UIView {
  11. var callback:((HotelMapData)->Void)?
  12. var mapHotelArr:[HotelMapData]?{
  13. didSet{
  14. self.tableView.reloadData()
  15. }
  16. }
  17. deinit {
  18. log.debug("IHMapResultView销毁")
  19. }
  20. lazy var tableView: UITableView = {
  21. let tableView = UITableView(frame: CGRect.zero, style: .plain)
  22. tableView.delegate = self
  23. tableView.dataSource = self
  24. tableView.backgroundColor = .clear
  25. tableView.separatorStyle = .none
  26. return tableView
  27. }()
  28. override init(frame: CGRect) {
  29. super.init(frame: frame)
  30. self.backgroundColor = .white
  31. addSubview(tableView)
  32. NotificationCenter.default.addObserver(self, selector: #selector(notifyReload(_:)), name: NSNotification.Name(kNotifactionIHMapResultViewReloadData), object: nil)
  33. }
  34. required init?(coder: NSCoder) {
  35. fatalError("init(coder:) has not been implemented")
  36. }
  37. @objc func notifyReload(_ notify: Notification){
  38. self.mapHotelArr = notify.object as? [HotelMapData]
  39. }
  40. override func layoutSubviews() {
  41. super.layoutSubviews()
  42. self.tableView.frame = CGRect(x: 0, y: 40 + 15, width: KSCREENWIDTH, height: self.bounds.size.height - 55)
  43. }
  44. }
  45. extension IHMapResultView:UITableViewDataSource,UITableViewDelegate{
  46. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  47. return self.mapHotelArr?.count ?? 0
  48. }
  49. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  50. var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
  51. if cell == nil {
  52. cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
  53. }
  54. cell?.selectionStyle = .none
  55. cell?.textLabel?.font = UIFont(name: PingFangSC_Medium, size: 12)
  56. cell?.textLabel?.textColor = UIColor(hexString: "#333333")
  57. let hotel = self.mapHotelArr![indexPath.row]
  58. cell?.textLabel?.text = hotel.name
  59. return cell!
  60. }
  61. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  62. let hotel = self.mapHotelArr![indexPath.row]
  63. if let block = self.callback {
  64. block(hotel)
  65. }
  66. }
  67. }