EGORefreshTableHeaderView

EGORefreshTableHeaderView

我对EGORefreshTableHeaderView的用法有疑问:

如果我使用此代码,可以:

 - (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView *)view
{
    _reloading = YES;
    [self performSelector:@selector(refreshData) withObject:nil afterDelay:0.1f];
}

 - (void)refreshData
{
    _reloading = NO;
   [self.dataSourceArr removeAllObjects];
   [self.dataSourceArr addNewData];
   [self.egoHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.mainTableView];
   [self.mainTableView reloadData];
}


但是,当我使用此代码时,EGOrefreshHeaderView始终显示在mainTableView顶部,但不会隐藏:

 - (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView *)view
{
    _reloading = YES;
    [self refreshData];
}
 - (void)refreshData
{
    _reloading = NO;
   [self.dataSourceArr removeAllObjects];
   [self.dataSourceArr addNewData];
   [self.egoHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.mainTableView];
   [self.mainTableView reloadData];
}

最佳答案

代码的最高位运行如下:

// someone calls egoRefreshTableHeaderDidTriggerRefresh
    [_delegate egoRefreshTableHeaderDidTriggerRefresh:self]
        // sets up a refreshData to run after set period of time
    scrollView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);  // a
// some time later, refreshData runs
    [self.egoHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.mainTableView];
        [scrollView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)];  // b


最低位运行如下:

// someone calls egoRefreshTableHeaderDidTriggerRefresh
    [_delegate egoRefreshTableHeaderDidTriggerRefresh:self]
        [self refreshData];
            [self.egoHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.mainTableView];
                [scrollView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)];  // b
    scrollView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);  // a


ab行颠倒了。即使更改具有动画效果,第二行也会覆盖第一行。

修复1:

修改文件EGORefreshTableHeaderView.h

- (void)egoRefreshTableHeaderDidTriggerRefresh:...更改为- (bool)egoRefreshTableHeaderDidTriggerRefresh:...

修改文件EGORefreshTableHeaderView.m

更改- (void)egoRefreshScrollViewDidEndDragging:

if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDidTriggerRefresh:)]) {
    if([_delegate egoRefreshTableHeaderDidTriggerRefresh:self]) {
       return;
    }
}


最后更改您的egoRefreshTableHeaderDidTriggerRefresh:

- (bool)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView *)view
{
    _reloading = YES;
    [self refreshData];
    return true;
}


修复2:

如果您不想更改第三方代码,则唯一的方法是最高版本。您可以将持续时间指定为0,这应该使选择器排队等待之后运行。

10-04 15:16