【发布时间】:2026-02-08 09:05:01
【问题描述】:
拉动刷新并没有消失。屏幕上只有 3 行可见,使用 print(indexPath.row) 后我可以看到它正在重新加载第 0、1、2 行,但刷新控件并没有消失。
override func viewDidLoad() {
super.viewDidLoad() ...
refreshControl = UIRefreshControl()
refreshControl!.addTarget(self, action: #selector(self.loadData), forControlEvents: UIControlEvents.ValueChanged)
refreshControl!.backgroundColor = UIColor.clearColor()
refreshControl!.tintColor = UIColor.clearColor()
tableView.addSubview(refreshControl!)...}
这里是 loadData 函数:
func loadData() {
venues = [CKRecord]()
let location = locationManager.location
let radius = CGFloat(1000)
let sort = CKLocationSortDescriptor(key: "Location", relativeLocation: location!)
let predicate = NSPredicate(format: "distanceToLocation:fromLocation:(%K,%@) < %f", "Location", location!, radius)
let publicData = CKContainer.defaultContainer().publicCloudDatabase
let query = CKQuery(recordType: "Venues", predicate: predicate )
query.sortDescriptors = [sort]
publicData.performQuery(query, inZoneWithID: nil) { (results:[CKRecord]?, error:NSError?) in
if let venues = results {
self.venues = venues
dispatch_async(dispatch_get_main_queue(), {
self.tableView.reloadData()
})
}
}
}
【问题讨论】:
-
试试我的代码,你的问题会很容易解决的。
标签: ios swift uitableview pull-to-refresh uirefreshcontrol