My refresh control doesn't disappear after the refresh progress is done. It remains animating, even though I call endRefreshing().
import UIKit
class MyTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
refreshControl = UIRefreshControl()
refreshControl?.attributedTitle = NSAttributedString(string: "Pull to refresh")
refreshControl?.addTarget(self, action: #selector(self.refresh), for: UIControlEvents.valueChanged)
tableView.addSubview(refreshControl!)
setData()
}
func setData(){
ApiClient.sharedInstance().getData{(myData, error) in
if (myData != nil){
DispatchQueue.main.async {
self.myLabel.text = myData
self.refreshControl?.endRefreshing()
}
}
if (error != nil){
print(error)
}
}
}
func refresh(sender:AnyObject) {
setData()
}
}
Can you help me?
beginUpdates and endUpdates did the magic.
This one drove me crazy for 1 hour. Finally this piece worked when my network call completes and refresh the table view.
class TransactionsViewConttroller : MyBaseTableViewController{
override func viewDidLoad() {
super.viewDidLoad()
self.refreshControl?.addTarget(self, action: #selector(refresh), for: .valueChanged)
}
@objc func refresh() {
justRefreshTransactions()
}
private func justRefreshTransactions(){
ServiceRequest.getLatestTransactions(completionBlock : {(error, errorMsg,result) in
self.stopRefrshIndic()
})
}
private func stopRefrshIndic(){
DispatchQueue.main.async {
self.tableView.beginUpdates()
self.refreshControl?.endRefreshing()
self.tableView.endUpdates()
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.