[英]UIRefreshControl not Dissapearing
刷新的吸引力并没有消失。 屏幕上只有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()
})
}
}
}
首先,这一行是错误的:
tableView.addSubview(refreshControl!)...}
您无需在iOS 10中的表视图中将刷新控件作为子视图添加。 它具有您设置的refreshControl
属性 :
tableView.refreshControl = refreshControl
其次,绝对正确的是刷新控件不会自行消失。 重新加载数据后,由您决定要向刷新控件发送endRefreshing()
消息。
dispatch_async(dispatch_get_main_queue(), {
self.tableView.reloadData()
self.tableView.refreshControl.endRefreshing()
})
尝试这个。
var refreshcontroller : UIRefreshControl = UIRefreshControl()
创建函数。
func refresh(sender:AnyObject) {
refreshcontroller.endRefreshing()
}
将此行放在您的viewDidLoad()中
您也可以在UIRefreshControl中添加图像
refreshcontroller = UIRefreshControl()
let rcImageView = UIImageView(image: UIImage(named: "refreshControl.png")!)
refreshcontroller.attributedTitle = NSAttributedString(string:"")
refreshcontroller.addTarget(self, action: #selector(self.refresh(_:)), forControlEvents: UIControlEvents.ValueChanged)
refreshcontroller.insertSubview(rcImageView, atIndex: 0)
self.Songlisttable.addSubview(refreshcontroller)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.