Reputation: 4042
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.
Upvotes: 8
Views: 14736
Reputation: 3510
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];
}
}
}
}
Upvotes: 4
Reputation: 1258
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
}
Upvotes: 24