iOS UITableView没有隐藏headerView

时间:2013-07-05 05:26:42

标签: ios uitableview refresh

我对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];
}

1 个答案:

答案 0 :(得分:1)

代码的最高位如下:

// 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,并且应该将选择器排队以在之后运行。