![](/img/trans.png)
[英]Swift Pull to Refresh with UIViewController without TableView or TableViewController
[英]iOS swift pull to refresh mixes with tableview
在我的表視圖控制器中,我實現了拉動刷新(UIRefreshControl)。 問題是我不知道為什么將它與tableView(UITableViewController)混合使用。 有關詳細信息,請參見屏幕截圖。 謝謝您的幫助!
您可以像這樣實現刷新控制。
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
@IBOutlet var tableView: UITableView!
var refreshControl : UIRefreshControl!
}
override func viewDidLoad() {
super.viewDidLoad()
self.refreshControl = UIRefreshControl()
self.refreshControl.backgroundColor = UIColor.clearColor()
self.refreshControl.tintColor = UIColor.blackColor()
self.refreshControl.addTarget(self, action: "methodPullToRefresh:", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(self.refreshControl)
}
func methodPullToRefresh(sender:AnyObject)
{
self.refreshControl?.beginRefreshing()
}
// Once you are done with your task
self.refreshControl?.endRefreshing()
// Main queue thread is only required when refresh controls comes or goes off with delay, if it works quickly then no need to add this
dispatch_async(dispatch_get_main_queue()) {
}
希望這能解決您的問題。
祝一切順利。
我有一個類似的問題,因此我解決了:
在View Controller上添加Refresh Controller時,有必要編寫以下代碼:
dispatch_async(dispatch_get_main_queue()) {
self.refreshControl.beginRefreshing()
self.refreshControl.endRefreshing()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.