refreshControl
是UIScrollView/UITableViewController
实例变量。 您正在尝试重新定义它,这就是导致错误的原因。 或者您当然可以使用提供的那个。self.refreshControl = UIRefreshControl()
Swift 4/5
override func viewDidLoad() {
super.viewDidLoad()
self.refreshControl = UIRefreshControl()
self.refreshControl!.attributedTitle = NSAttributedString(string: "Pull to refresh")
self.refreshControl!.addTarget(self, action: #selector(refresh(sender:)), for: UIControl.Event.valueChanged)
}
@objc func refresh(sender:AnyObject) {
// Code to refresh table view
self.refreshControl!.endRefreshing()
}
let tableView: UITableView = CoolTableViewSubclass()
tableView.refreshControl = nil // but my overridden property can't be nil!