// // IHActivityHistoryView.swift // Inhealth // // Created by weclouds on 2019/12/19. // Copyright © 2019 weclouds. All rights reserved. // import UIKit import ESPullToRefresh let kNotifactionIHActivityHistoryViewGetlogList = "kNotifactionIHActivityHistoryViewGetlogList" protocol IHActivityHistoryViewDelegate : NSObjectProtocol{ func tableViewEsAddPullToRefresh() func tableViewEsAddInfiniteScrolling() } class IHActivityHistoryView: UIView { weak var delegate : IHActivityHistoryViewDelegate? var logList:[LogData]? lazy var tableView: UITableView = { let tableView = UITableView(frame: .zero, style: .plain) tableView.delegate = self tableView.dataSource = self tableView.allowsSelection = true tableView.separatorStyle = .none tableView.register(UINib(nibName: "IHActivityHistoryCell", bundle: nil), forCellReuseIdentifier: "cell") return tableView }() override init(frame: CGRect) { super.init(frame: frame) addSubview(tableView) NotificationCenter.default.addObserver(self, selector: #selector(notifyLoglist), name: NSNotification.Name(kNotifactionIHActivityHistoryViewGetlogList), object: nil) //设置下滑刷新,上拉加载更多 let header = KKWRefreshHeaderAnimator(frame: CGRect.zero) let footer = ESRefreshFooterAnimator(frame: CGRect.zero) //下拉刷新 tableView.es.addPullToRefresh(animator: header) { self.delegate?.tableViewEsAddPullToRefresh() } //上拉加载更多 tableView.es.addInfiniteScrolling(animator: footer) { self.delegate?.tableViewEsAddInfiniteScrolling() } } func endRefresh(){ tableView.es.stopPullToRefresh() tableView.es.stopLoadingMore() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func layoutSubviews() { super.layoutSubviews() self.tableView.frame = self.bounds } @objc func notifyLoglist(_ notif: Notification) { let _loglist = notif.object as! [LogData]? self.logList = _loglist self.tableView.reloadData() } deinit { NotificationCenter.default.removeObserver(self) } } extension IHActivityHistoryView:UITableViewDelegate,UITableViewDataSource{ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return logList?.count ?? 0 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! IHActivityHistoryCell cell.selectionStyle = .none cell.log = logList![indexPath.row] return cell } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 104 } }