UIRefreshControl for uitableview is not working in only iphone 6

799 views Asked by At

Actually this working is fine in all devices except IPhone-6. Please help me for this problem.

my code is

var refreshControl = UIRefreshControl()

        self.refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
        self.tableView.addSubview(self.refreshControl)


func refresh(_ sender:AnyObject) {
    if self.appDel.isNetworkEnabled
    {
        DispatchQueue.main.async {
            if(self.page < Int(self.total_pages)! )
            {
                self.page = self.page + 1
                self.fetchMessageApiCall()
            }
        }
    }
    else
    {
        self.singletonObj.showAlert("", message: "No Internet")
    }

    self.refreshControl.endRefreshing()
}
3

There are 3 answers

3
PiyushRathi On

Just allocate refresh controller like this:

    let tableViewControler = UITableViewController()
    tableViewControler.tableView = self.tableView
    self.refreshController = UIRefreshControl()
    self.refreshController.tintColor = UIColor(red: 87.0/255.0, green: 53.0/255.0, blue: 129.0/255.0, alpha: 1.0)
    let attributedString = NSAttributedString(string: "Refresh")
    self.refreshController.attributedTitle = attributedString
    self.refreshController.addTarget(self, action:#selector(self.refresh(_:)), forControlEvents: UIControlEvents.ValueChanged)
    tableViewControler.refreshControl = self.refreshController

hope this helps

0
nebuchadnezzar On

May be you should put this self.refreshControl.endRefreshing() when your are done fetching data from API.

0
krish On

SWIFT 3.0

I faced this issue in IOS 10 and above, and resolved it using below code

refreshControl = UIRefreshControl()

refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
refreshControl.addTarget(self, action: #selector(refresh(sender:)), for: UIControlEvents.valueChanged)
    if #available(iOS 10.0, *) {
        self.gigListTableView.refreshControl = refreshControl
    } else {
        // Fallback on earlier versions
        self.gigListTableView.addSubview(refreshControl)
    }