简体   繁体   中英

UIRefreshControl in tableview dies when try pull to refresh

In this class apparently all is in good condition (xcode 10.0), but after i updated to xcode 10.2, every viewController i have the same structure it crashes and now, apparently the app can't recognize the refreshControl when i try pull to refresh. Here is a sample code:

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

  @IBOutlet weak var tableView: UITableView!

  var refresh           : UIRefreshControl!

  override func viewDidLoad() {
      super.viewDidLoad()
      self.refresh = UIRefreshControl()
      self.refresh.tintColor = UIColor.red
      self.refresh.attributedTitle = NSAttributedString(string: "Update data")
      self.refresh.addTarget(self, action: #selector(self.refreshMethod), for: .valueChanged)
      self.tableView.addSubview(self.refresh)
  }

  @objc func refreshMethod(){
      self.httpGETRequest()
  }
...
}

The solution for me was to put @objc func refreshMethod(_ refreshControl: UIRefreshControl){... in my original code and now it works as allways.

@IBOutlet weak var tableView: UITableView!

var refresh           : UIRefreshControl!

override func viewDidLoad() {
    super.viewDidLoad()
    self.refresh = UIRefreshControl()
    self.refresh.tintColor = UIColor.red
    self.refresh.attributedTitle = NSAttributedString(string: "Update data")
    self.refresh.addTarget(self, action: #selector(self.refreshMethod), for: .valueChanged)
    self.tableView.addSubview(self.refresh)
}

@objc func refreshMethod(_ refreshControl: UIRefreshControl){
  //Now it is obligatory to make the pull to refresh functional...
    self.httpGETRequest()
}
...

Best regards

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM