// // IHMapResultView.swift // Inhealth // // Created by weclouds on 2020/5/22. // Copyright © 2020 weclouds. All rights reserved. // import UIKit let kNotifactionIHMapResultViewReloadData = "kNotifactionIHMapResultViewReloadData" class IHMapResultView: UIView { var callback:((HotelMapData)->Void)? var mapHotelArr:[HotelMapData]?{ didSet{ self.tableView.reloadData() } } deinit { log.debug("IHMapResultView销毁") } lazy var tableView: UITableView = { let tableView = UITableView(frame: CGRect.zero, style: .plain) tableView.delegate = self tableView.dataSource = self tableView.backgroundColor = .clear tableView.separatorStyle = .none return tableView }() override init(frame: CGRect) { super.init(frame: frame) self.backgroundColor = .white addSubview(tableView) NotificationCenter.default.addObserver(self, selector: #selector(notifyReload(_:)), name: NSNotification.Name(kNotifactionIHMapResultViewReloadData), object: nil) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } @objc func notifyReload(_ notify: Notification){ self.mapHotelArr = notify.object as? [HotelMapData] } override func layoutSubviews() { super.layoutSubviews() self.tableView.frame = CGRect(x: 0, y: 40 + 15, width: KSCREENWIDTH, height: self.bounds.size.height - 55) } } extension IHMapResultView:UITableViewDataSource,UITableViewDelegate{ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.mapHotelArr?.count ?? 0 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { var cell = tableView.dequeueReusableCell(withIdentifier: "cell") if cell == nil { cell = UITableViewCell(style: .default, reuseIdentifier: "cell") } cell?.selectionStyle = .none cell?.textLabel?.font = UIFont(name: PingFangSC_Medium, size: 12) cell?.textLabel?.textColor = UIColor(hexString: "#333333") let hotel = self.mapHotelArr![indexPath.row] cell?.textLabel?.text = hotel.name return cell! } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let hotel = self.mapHotelArr![indexPath.row] if let block = self.callback { block(hotel) } } }