Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS How to Implement UITableView Bottom Refresh Control [duplicate]

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.

like image 671
Imran Hishaam Avatar asked Apr 24 '15 04:04

Imran Hishaam


2 Answers

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 !!

like image 84
Viral Savaj Avatar answered Sep 28 '22 16:09

Viral Savaj


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.

like image 26
Imran Hishaam Avatar answered Sep 28 '22 15:09

Imran Hishaam