Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add pull tableview up to refresh data inside the uitableview

I know how to add pull-to-refresh into a view controller. But right now the situations is: I have a UIView & that contains a UITableView and I want to pull the table view up at the very bottom of tableview to reload it's data.

How to add pull-to-refresh inside this UITableView, not it's parent view's controller.

like image 406
yong ho Avatar asked May 31 '13 07:05

yong ho


People also ask

How do you add a pull to refresh to a table view or collection view?

You can add a refresh control to a table or collection view by assigning an instance of the UIRefreshControl class to this property. If your application targets versions prior to iOS 10, you simply add the refresh control as a subview to the table view.


2 Answers

In your ViewDidLoad add this:

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
[self.myTableView addSubview:refreshControl];

And refresh

- (void)refresh:(id)sender
{
// do your refresh here and reload the tablview
}
like image 158
vin Avatar answered Oct 16 '22 16:10

vin


it's simple: Take one UIScrollView and inside it take UITableview and put in bottom of UITableView and just write Scrollview delegate method

    #pragma mark -
    #pragma mark - Scroll View Delegate Method

    - (void) scrollViewDidScroll:(UIScrollView *)scrollView {

        if (scrollView == scrollObj) {
            CGFloat scrollPosition = scrollObj.contentSize.height - scrollObj.frame.size.height - scrollObj.contentOffset.y;
            if (scrollPosition < 30)// you can set your value
            {
                if (!spinnerBottom.isAnimating) {
                    [spinnerBottom startAnimating];
                    [self YourPUllToRefreshMethod];
                }
            }
        }
    }
like image 26
SAMIR RATHOD Avatar answered Oct 16 '22 14:10

SAMIR RATHOD