IHTPickerAreaCell.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // IHTPickerAreaCell.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2020/3/17.
  6. // Copyright © 2020 weclouds. All rights reserved.
  7. //
  8. //如果啥都没做,就点击保存???
  9. //如果啥都没做
  10. import UIKit
  11. protocol IHTPickerAreaCellDelegate : NSObjectProtocol{
  12. func selectedCity(_ indexPath :IndexPath)
  13. }
  14. class IHTPickerAreaCell: UITableViewCell {
  15. var cityCallback:((DropDownData)->Void)?
  16. var cityList :[DropDownData]?{
  17. didSet{
  18. if let citylist = self.cityList {
  19. if citylist.count > 0 {
  20. self.scrollView?.removeSubviews()
  21. self.scrollView?.addSubview(buttonView)
  22. self.buttonView.frame = CGRect(x: 10, y: 0, width: KSCREENWIDTH - 20, height: culAreaCellHeight(citylist.count))
  23. self.scrollView?.contentSize = CGSize(width: 0, height: culAreaCellHeight(citylist.count))
  24. self.buttonView.reloadData()
  25. }
  26. }
  27. }
  28. }
  29. lazy var buttonView: IHButtonView = {
  30. let buttonView = IHButtonView()
  31. buttonView.delegate = self
  32. return buttonView
  33. }()
  34. var scrollView:UIScrollView?
  35. override func awakeFromNib() {
  36. super.awakeFromNib()
  37. scrollView = UIScrollView()
  38. self.contentView.addSubview(scrollView!)
  39. }
  40. override func setSelected(_ selected: Bool, animated: Bool) {
  41. super.setSelected(selected, animated: animated)
  42. }
  43. override func layoutSubviews() {
  44. super.layoutSubviews()
  45. self.scrollView?.frame = self.bounds
  46. }
  47. //这里只处理大于0的情况 小于零不创建
  48. func culAreaCellHeight(_ cityCount: Int) ->CGFloat {
  49. //计算行数
  50. let row : Int = cityCount / 4
  51. let contentViewHight = 30 * (row + 1) + 10 + 10 + 10 * row
  52. return CGFloat(contentViewHight)
  53. }
  54. }
  55. extension IHTPickerAreaCell:IHButtonViewDelegate{
  56. func numberofItem(in buttonView: IHButtonView) -> Int {
  57. return self.cityList?.count ?? 0
  58. }
  59. func buttonView(_ buttonView: IHButtonView, titleFor item: Int) -> String {
  60. return self.cityList![item].name!
  61. }
  62. func buttonView(_ buttonView: IHButtonView, didSelected item: Int) {
  63. log.debug(self.cityList![item].name!)
  64. let city = self.cityList![item]
  65. Intermediate.cityId = city.id!
  66. Intermediate.cityName = city.name!
  67. if let block = self.cityCallback {
  68. block(self.cityList![item])
  69. }
  70. }
  71. }