// // IHHotelView.swift // Inhealth // // Created by weclouds on 2019/12/12. // Copyright © 2019 weclouds. All rights reserved. // import UIKit import JXPagingView class IHHotelView: UIView , UIScrollViewDelegate{ var hotels :[HotelViewData]? { return Intermediate.share.hotels } lazy var tableView: UITableView = { let tableView = UITableView(frame:self.bounds, style: .plain) tableView.dataSource = self tableView.delegate = self return tableView }() var listViewDidScrollCallback: ((UIScrollView) -> ())? override init(frame: CGRect) { super.init(frame: frame) addSubview(tableView) self.backgroundColor = UIColor.white self.tableView.backgroundColor = UIColor.white tableView.separatorStyle = .none // for i in 0..<10 { // let cellid = "cell" + "\(i)" // tableView.register(UINib(nibName: "IHHotelCell", bundle: nil), forCellReuseIdentifier: cellid) // } } deinit { NotificationCenter.default.removeObserver(self) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func layoutSubviews() { super.layoutSubviews() tableView.frame = self.bounds self.tableView.reloadData() } } extension IHHotelView:UITableViewDataSource,UITableViewDelegate{ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.hotels?.count ?? 0 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { // let cellid = "cell" + "\(indexPath.row)" // let cell = tableView.dequeueReusableCell(withIdentifier: cellid) as! IHHotelCell // // cell.selectionStyle = .none // let lineView = IHDashView(strokeColor: UIColor(hexString: "C6CDD5", transparency: 0.5)?.cgColor, gap: 3, lineWith: 1) // cell.addSubview(lineView) let hotel = self.hotels![indexPath.row] var cell : IHHotelCell? if hotel.type! == "0" { cell = tableView.dequeueReusableCell(withIdentifier: "IHHotelCell") as? IHHotelCell if cell == nil{ cell = Bundle.main.loadNibNamed("IHHotelCell", owner: nil, options: nil)?.first as? IHHotelCell } }else{ cell = tableView.dequeueReusableCell(withIdentifier: "SchoolCell") as? IHHotelCell if cell == nil{ cell = Bundle.main.loadNibNamed("IHHotelCell", owner: nil, options: nil)?.last as? IHHotelCell } } cell?.selectionStyle = .none for line in cell!.subviews { if line.isKind(of: IHDashView.self){ line.removeFromSuperview() } } let lineView = IHDashView(strokeColor: UIColor(hexString: "C6CDD5", transparency: 0.5)?.cgColor, gap: 3, lineWith: 1) cell?.addSubview(lineView) //let hotel = self.hotels![indexPath.row] if hotel.alarmCount == "0" { if hotel.type! == "0"{ lineView.frame = CGRect(x: 20, y: 230 - 52 - 1, width: KSCREENWIDTH - 40 , height: 1) }else{ lineView.frame = CGRect(x: 20, y: 264 - 52 - 1, width: KSCREENWIDTH - 40 , height: 1) } }else{ if hotel.type! == "0" { lineView.frame = CGRect(x: 20, y: 230 - 1, width: KSCREENWIDTH - 40 , height: 1) }else{ lineView.frame = CGRect(x: 20, y: 264 - 1, width: KSCREENWIDTH - 40 , height: 1) } } cell!.hotel = hotel return cell! } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { let hotel = self.hotels![indexPath.row] if hotel.alarmCount == "0" { if hotel.type! == "0" { return 230 - 52 }else{ return 264 - 52 } }else{ if hotel.type! == "0" { return 230 }else{ return 264 } } } func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { let hotel = self.hotels![indexPath.row] if hotel.alarmCount == "0" { return 230 - 52 }else{ return 230 } } func scrollViewDidScroll(_ scrollView: UIScrollView) { self.listViewDidScrollCallback?(scrollView) } } extension IHHotelView:JXPagingViewListViewDelegate{ func listView() -> UIView { return self } func listScrollView() -> UIScrollView { return self.tableView } func listViewDidScrollCallback(callback: @escaping (UIScrollView) -> ()) { self.listViewDidScrollCallback = callback } }