Why is the isEnabled property in the PullToRefresh.swift file default to false?
GrooveCoverage opened this issue · 0 comments
GrooveCoverage commented
I wrote the following code using SnapKit
static let baseCellIdentifier = "baseCellIdentifier"
lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.backgroundColor = UIColor.lightGray
tableView.contentInsetAdjustmentBehavior = .never
tableView.delegate = self
tableView.dataSource = self
tableView.showsHorizontalScrollIndicator = false
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 44
tableView.register(BaseTableViewCell.classForCoder(), forCellReuseIdentifier: ViewController.baseCellIdentifier)
tableView.estimatedSectionHeaderHeight = 0
tableView.estimatedSectionFooterHeight = 0
tableView.sectionHeaderHeight = 0.01
tableView.sectionFooterHeight = 0.01
let tableHeadView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 0.01))
tableView.tableHeaderView = tableHeadView
let tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 0.01))
tableView.tableFooterView = tableFooterView
return tableView
}()
view.addSubview(tableView)
tableView.snp.makeConstraints { (maker) in
maker.edges.equalTo(view.safeAreaLayoutGuide)
}
tableView.addPullToRefresh(PullToRefresh()) {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) { [weak self] in
self?.tableView.endRefreshing(at: .top)
}
}
tableView.addPullToRefresh(PullToRefresh(position: .bottom)) {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) { [weak self] in
self?.tableView.endRefreshing(at: .bottom)
}
}
Then I encountered the problem that endRefreshing could not stop. I compared your demo and found that your demo will trigger the didSet of the state attribute when initially addPullToRefresh(PullToRefresh(position: .bottom), but mine didn’t trigger it(the didSet of the state attribute) once at the beginning. I don’t know why, but I temporarily solved the problem after setting the isEnabled attribute to true by default. When the two controls were just added, the initial state was initial. Shouldn’t the isEnabled attribute default to true?
My English is not very good. Can you understand the problem I described? Hope to give me some suggestions, thank you!