iOS快速拉动与tableview刷新混合

时间:2015-04-03 16:02:41

标签: ios uitableview swift uirefreshcontrol

在我的表视图控制器中,我实现了pull to refresh(UIRefreshControl)。问题是我不知道为什么它与tableView(UITableViewController)混合。有关详细信息,请参见屏幕截图谢谢你的帮助!

pull to refresh mix with tableView

2 个答案:

答案 0 :(得分:2)

您可以像这样实现刷新控制。

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()

}

enter image description here

// 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()) {

}

enter image description here

希望,这将解决您的问题。

一切顺利。

答案 1 :(得分:0)

我遇到了类似的问题,我解决了这个问题:

在View Controller上添加Refresh Controller时,需要编写以下代码:

dispatch_async(dispatch_get_main_queue()) {
    self.refreshControl.beginRefreshing()
    self.refreshControl.endRefreshing()
}
相关问题