| | |
| | | @IBOutlet weak var tableView: UITableView! |
| | | @IBOutlet weak var cons_tableHeight: NSLayoutConstraint! |
| | | private var closeClouse:(()->Void)? |
| | | private var clouse:((String)->Void)? |
| | | private var clouse:((NormalSimpleModel)->Void)? |
| | | private var items = [NormalSimpleModel]() |
| | | private var selectModel:NormalSimpleModel? |
| | | |
| | | override func awakeFromNib() { |
| | | super.awakeFromNib() |
| | | |
| | | tableView.delegate = self |
| | | tableView.dataSource = self |
| | | tableView.separatorStyle = .none |
| | | tableView.register(UINib(nibName: "Common_1_TCell", bundle: nil), forCellReuseIdentifier: "_Common_1_TCell") |
| | | alpha = 0 |
| | | cons_tableHeight.constant = 0 |
| | | layoutIfNeeded() |
| | | } |
| | | |
| | | static func show(inView:UIView,afterView:UIView,items:[String],clouse:@escaping (String)->Void,closeClouse:@escaping ()->Void){ |
| | | static func show(inView:UIView,afterView:UIView,items:[NormalSimpleModel],selectModel:NormalSimpleModel? = nil,clouse:@escaping (NormalSimpleModel)->Void,closeClouse:@escaping ()->Void)->CourseSubTypeView{ |
| | | let subTypeView = CourseSubTypeView.jq_loadNibView() |
| | | subTypeView.closeClouse = closeClouse |
| | | subTypeView.clouse = clouse |
| | | subTypeView.items = items |
| | | subTypeView.selectModel = selectModel |
| | | inView.addSubview(subTypeView) |
| | | subTypeView.snp.makeConstraints { make in |
| | | make.top.equalTo(afterView.snp.bottom) |
| | |
| | | UIView.animate(withDuration: 0.2) { |
| | | subTypeView.alpha = 1 |
| | | } completion: { _ in |
| | | subTypeView.cons_tableHeight.constant = 220 |
| | | subTypeView.cons_tableHeight.constant = CGFloat(min(items.count * 50, 250)) |
| | | UIView.animate(withDuration: 0.2) { |
| | | subTypeView.layoutIfNeeded() |
| | | subTypeView.tableView.reloadData() |
| | | } |
| | | } |
| | | |
| | | return subTypeView |
| | | } |
| | | |
| | | @IBAction func closeAction(_ sender: UIButton) { |
| | |
| | | self.alpha = 0 |
| | | self.layoutIfNeeded() |
| | | } completion: { _ in |
| | | self.clouse?("") |
| | | let item = self.items[indexPath.row] |
| | | self.clouse?(item) |
| | | self.closeClouse?() |
| | | } |
| | | } |
| | | } |
| | | |
| | | extension CourseSubTypeView:UITableViewDataSource{ |
| | | |
| | | func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { |
| | | return 50 |
| | | } |
| | | |
| | | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_Common_1_TCell") as! Common_1_TCell |
| | | |
| | | let item = items[indexPath.row] |
| | | cell.label_content.text = item.name |
| | | if selectModel == nil{ |
| | | cell.isSelected = indexPath.row == 0 |
| | | }else{ |
| | | cell.isSelected = selectModel?.name == item.name |
| | | } |
| | | return cell |
| | | } |
| | | |
| | | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
| | | return 10 |
| | | return items.count |
| | | } |
| | | |
| | | |