Pull to Refresh in UiTableView with Animations: In UITableView we show cells linearly and can reload whole table view by calling one reload function of UITableView anywhere in your code as per you want on any button action or on any progress of method or in middle of any task. As you have seen in many apps that by pulling UITableView as can see reloading of content happens, so from that you can get an basic idea that you have to set action on that pulling of UITableView.
How to Make Pull to Refresh in UiTableView with Animations?
Contents
OVERVIEW ON PULL-TO-REFRESH IN UITABLEVIEW
Calling APIs and reading that response data and then parsing of that data, after these we show or display that data in UI of Screen where user can interact with but in some cases you have to put an option by which user can update that data whenever he wants to control should be on user hand so we put a refresh button on navigation bar for this purpose but now days of animation we prefer pulling of UITableView is much easier and user friendly way to refresh content.
CODE FOR PULL-TO-REFRESH IN UITABLEVIEW
Firstly declare a variable UIRefreshControl which is a standard control that can initiate the refreshing of a scroll view’s contents.
You can use a refresh control in a scroll view or an object that inherits from UIScrollView, such as UITableVIew or UICollectionView.
UIRefreshControl *refreshController;
Then after declaring this implement below code in viewDidLoad Method
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view.
refreshController = [[UIRefreshControl alloc] init];
[refreshController addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
}
And after this implement action method
#pragma mark - Handle Refresh Method
-(void)handleRefresh : (id)sender
{
NSLog (@"Pull To Refresh Method is being called here“);
//call method here you as you want
[refreshController endRefreshing];
}