0

In my tableView I need to have self.tableView.tableFooterView = UIView() otherwise the table scrolls too far down. The problem is if I add this then my pull to refresh UIRefreshControl no longer works. Is there a way to have both?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
bdc
  • 178
  • 1
  • 12

2 Answers2

1

There's no reason why you can't have both. Have you added the UIRefreshControl in the right way? Here's working code from a project of mine:

var pullToRefreshControl : UIRefreshControl!

override func viewDidLoad() {
        super.viewDidLoad()

        self.setFooterView()
        self.addPullToRefreshView()
    }

private func setFooterView() {

        let footerView = UIView()

        let footerLabel = UILabel()
        footerLabel.text = "Table Footer"
        footerLabel.sizeToFit()
        footerView.addSubview(footerLabel)

        self.tableView.tableFooterView = footerView
    }

private func addPullToRefreshView() {

        pullToRefreshControl = UIRefreshControl()
        pullToRefreshControl.attributedTitle = NSAttributedString(string: "Pull To Refresh")
        pullToRefreshControl.addTarget(self, action: "refresh:", forControlEvents: .ValueChanged)

        self.tableView.addSubview(pullToRefreshControl!)
    }
Vinod Vishwanath
  • 5,821
  • 2
  • 26
  • 40
  • Yeah I tried this exact code in my project and it did not work. (I had to delete -> UIVIew since there's no return). For some reason the footer is preventing all scrolling. – bdc Apr 07 '16 at 15:42
  • One little note that could make all the difference - set the tableview style as `Grouped` instead of Plain, either in InterfaceBuilder or by code. – Vinod Vishwanath Apr 07 '16 at 15:44
  • Sorry. Solved it! I had self.tableView.alwaysBounceVertical = false which caused the refreshed not to work – bdc Apr 07 '16 at 16:29
  • Glad you figured it out! – Vinod Vishwanath Apr 07 '16 at 18:11
-1

Make a Custom Control refresh control for This

atul awasthi
  • 113
  • 1
  • 11