简体   繁体   中英

iOS swift pull to refresh mixes with tableview

In my table view controller, i have implemented pull to refresh (UIRefreshControl). The problem is that I do not know why it is mix with the tableView (UITableViewController). For details, see the screenshot. Thank you for your assistance!

拉刷新与tableView混合

You can implement refresh control like this.

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

}

在此处输入图片说明

Hope, this will resolve your problem.

All the best.

I had a similar problem and I solved it so:

When adding Refresh Controller on View Controller it is necessary to write the following code:

dispatch_async(dispatch_get_main_queue()) {
    self.refreshControl.beginRefreshing()
    self.refreshControl.endRefreshing()
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM