123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //
- // 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)
- }
- }
-
- }
|