我正在向tableView添加刷新控件。
然后从顶部的代码dosent show开始设置动画。我必须滚动tableView向下。
在此之后我将搜索控件添加到navbaritem,然后它看起来像:
这是代码
lazy var customRefreshControl: UIRefreshControl = {
let control = UIRefreshControl()
control.attributedTitle = NSAttributedString(string: "Downloading Locations")
control.addTarget(self, action: #selector(updateLocation), for: .valueChanged)
return control
}()
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.largeTitleDisplayMode = .automatic
searchController = UISearchController(searchResultsController: nil)
searchController.searchBar.tintColor = .white
searchController.searchBar.delegate = self
tableView.addSubview(customRefreshControl)
title = "location_groups".localized()
tableView.tableFooterView = UIView()
tableView.backgroundColor = .groupTableViewBackground
navigationItem.searchController = searchController
searchController.dimsBackgroundDuringPresentation = false
}
func loadLocationGroups() {
DispatchQueue.global(qos: .userInteractive).async { [unowned self] in
self.locationGroups = DataBaseManager.Instance.GetLocations()
DispatchQueue.main.async {
self.tableView.reloadData()
if self.locationGroups.isEmpty {
self.customRefreshControl.attributedTitle = NSAttributedString(string: "Downloading Locations")
} else {
self.customRefreshControl.attributedTitle = NSAttributedString(string: "Synchronize")
}
self.customRefreshControl.beginRefreshing()
}
self.request(requestType: .getLocationGroups)
}
}