// // IHAreaListView.swift // Inhealth // // Created by weclouds on 2019/12/13. // Copyright © 2019 weclouds. All rights reserved. // import UIKit protocol IHAreaListViewDelegate : NSObjectProtocol { func areaListViewDidSelectRowAt(indexPath: IndexPath) } class IHAreaListView: UIView { var roomList : [RoomData]? { didSet{ self.tableView.reloadData() } } weak var listDelegate : IHAreaListViewDelegate? lazy var tableView: UITableView = { let tableView = UITableView(frame: CGRect.zero, style: .plain) tableView.delegate = self tableView.dataSource = self tableView.backgroundColor = UIColor(hexString: "#F6F8F7") tableView.separatorStyle = .none //tableView.register(UINib(nibName: "IHAreaListCell", bundle: nil), forCellReuseIdentifier: "cell") return tableView }() override init(frame: CGRect) { super.init(frame: frame) addSubview(tableView) } override func layoutSubviews() { super.layoutSubviews() self.tableView.frame = self.bounds // self.tableView.frame = CGRect.init(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } extension IHAreaListView:UITableViewDataSource,UITableViewDelegate{ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.roomList?.count ?? 0 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! IHAreaListCell // cell.selectionStyle = .none // let room = self.roomList![indexPath.row] // cell.room = room // return cell let room = self.roomList![indexPath.row] var cell : IHAreaListCell? if room.type == "1"{ //学校 cell = tableView.dequeueReusableCell(withIdentifier: "ClassRoom") as? IHAreaListCell if cell == nil{ cell = Bundle.main.loadNibNamed("IHAreaListCell", owner: nil, options: nil)?.last as? IHAreaListCell cell!.selectionStyle = .none } }else{ //酒店 cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? IHAreaListCell if cell == nil{ cell = Bundle.main.loadNibNamed("IHAreaListCell", owner: nil, options: nil)?.first as? IHAreaListCell cell!.selectionStyle = .none } } cell!.room = room return cell! } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 150 } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if let delegate = listDelegate { delegate.areaListViewDidSelectRowAt(indexPath: indexPath) } } }