![](/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.