How to programmatically force EGORefreshTableHeaderView to update

I am trying to get EGORefreshTableHeaderView update the code. When I pull everything out, everything works fine, and the TableView (root) is updated. But I have a modal view where the user can subscribe to certain entities. When it subscribes to one, the restart method is launched in the first (root) view of the table. This method establishes a connection to the server, downloads certain data based on the subscription, saves it in CoreData DB and updates the TableView (root).

The problem is that when a user is connected only to 3G or Edge networks, downloading that is processed in its own stream may take several seconds. To tell the user that something is happening, I would like to show an EGORefreshTableHeaderView .

I found out that I can indent the update view and manually show the download icon, but I was wondering if there was a simpler solution by simply calling the delegate or method on EGORefreshTableHeaderView ?

+4
source share
2 answers

Have you tried using egoRefreshScrollViewDataSourceStartManualLoading ?

Assuming your EGORefreshTableHeaderView instance EGORefreshTableHeaderView named _refreshTableHeaderView, then a call like:

 [_refreshTableHeaderView egoRefreshScrollViewDataSourceStartManualLoading:self.tableView]; 

works for me ...


So, it has been too long since I used it and I forgot that I applied this change myself ...

I modified EGORefreshTableHeaderDelegate (declared in EGORefreshTableHeaderView.h ) to add this additional protocol:

 - (void)egoRefreshScrollViewDataSourceStartManualLoading:(UIScrollView *)scrollView; 

And the implementation (in EGORefreshTableHeaderView.m ):

 - (void)egoRefreshScrollViewDataSourceStartManualLoading:(UIScrollView *)scrollView { [self setState:EGOOPullRefreshLoading]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.2]; scrollView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f); [UIView commitAnimations]; if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDidTriggerRefresh:)]) { [_delegate egoRefreshTableHeaderDidTriggerRefresh:self]; } } 

Let me know if you need more help.

(And I thank Huge for a great job!)

+9
source

Thanks to Reuven and his code, I improved it a bit so that it can also be used in a UIScrollView, which is larger in screen size. In addition, I modified the deprecated commitAnimations to block the animation.

 #pragma mark - Manually refresh view update - (void)egoRefreshScrollViewDataSourceStartManualLoading:(UIScrollView *)scrollView { [self.refreshHeaderView setState:EGOOPullRefreshLoading]; //animating pull down scroll view [UIView animateWithDuration:0.2 animations:^{ scrollView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f); scrollView.contentOffset = CGPointMake(0, -60.0f); } ]; //triggering refreshview regular refresh if ([self.tableView.delegate respondsToSelector:@selector(egoRefreshTableHeaderDidTriggerRefresh:)]) { [self egoRefreshTableHeaderDidTriggerRefresh:self.refreshHeaderView]; } } 
+1
source

Source: https://habr.com/ru/post/1412956/


All Articles