2

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!

pull to refresh mix with tableView

Hasya
  • 9,792
  • 4
  • 31
  • 46
mazorati
  • 2,031
  • 3
  • 22
  • 22

2 Answers2

3

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

}

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

Hope, this will resolve your problem.

All the best.

Hasya
  • 9,792
  • 4
  • 31
  • 46
0

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()
}
Ilia Khalyapin
  • 148
  • 1
  • 7