5

I just want to know if there's a way to implement the bottom refresh control with the use of UIRefreshControl without any third party libraries.

Thanks in advance.

Imran Hishaam
  • 141
  • 1
  • 10
  • 1
    No, this is not a customization option for UIRefreshControl. You could just set up your table to refresh its data when it scrolls to the bottom if you're ok not having the refresh control animation. – DanielG Apr 24 '15 at 04:13
  • 1
    This should be what you are looking for: http://stackoverflow.com/questions/14942460/uirefreshcontrol-at-the-bottom-of-the-uitableview-ios6 – Kaey Apr 24 '15 at 04:45

3 Answers3

4

You can add footer to the tableview section, set Refresh view, with func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView?, if the footer get load then call the next set Refresh animation kind of things.

May solve your problem with such way.

HTH, Enjoy Coding !!

Viral Savaj
  • 3,379
  • 1
  • 26
  • 39
  • I believe this is the logical, simple solution without reinventing the wheel. And should be followed by everybody who searches for bottom refresh. Really can't understand why complicating yourself with playing with the scroll view kind of solution which can add unexpected behaviour in some edge cases. – Fawkes Jan 31 '16 at 17:37
3

Alright so after some time and with all the comments and answers above i came up with something.

with the use of scrollViewDidScroll i have implemented bottom refresh

if the UIScrollView have reached Bottom it slides up a UIView and after the execution it auto slides back down and reloads the UITableView.

The scrollViewDidScroll function

 func scrollViewDidScroll(scrollView: UIScrollView) {
    let scrollOffset : CGFloat = scrollView.contentOffset.y
    let scrollHeight : CGFloat = scrollView.frame.size.height

    let scrollContentSizeHeight : CGFloat = scrollView.contentSize.height + scrollView.contentInset.bottom

    let tableFrame : CGRect = self.tableView.frame

    if (scrollOffset + scrollHeight) >= scrollContentSizeHeight {
        self.bottomRefreshAnimation()
    } else {
        if self.tableView.frame.origin.y < 0 {
            UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                self.tableView.frame.origin.y = self.tableView.frame.origin.y + 40
                }, completion: nil)
        }
    }
}

and the self.bottomRefreshAnimation() contains the code to animate the UIView from the bottom

 func bottomRefreshAnimation(){
    if self.tableView.frame.origin.y > 0 {

        UIView.animateWithDuration(0.4, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
            self.tableView.frame.origin.y = self.tableView.frame.origin.y - 40
            }, completion: nil)

        populateData({ (finished) -> () in
            UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                    if self.tableView.frame.origin.y < 0 {
                        self.tableView.frame.origin.y = self.tableView.frame.origin.y + 40
                    }
                }, completion: nil)
        })
    }
}

Most importantly what it does is it checks for the UITableView Origin.y and reduces the size by 40 while the UIView is sliding up.

Hopefully this will help you guys and if there are better ways to achieve this please let me know

Thanks for all the reply's.

Imran Hishaam
  • 141
  • 1
  • 10
1

This should be what you are looking for: UIRefreshControl at the bottom of the UITableView iOS6?

You can also refresh any row of a tableView using:

[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
Community
  • 1
  • 1
Kaey
  • 4,615
  • 1
  • 14
  • 18