有一个按钮来激活EGORefreshTableHeaderView

时间:2012-07-20 10:06:32

标签: iphone objective-c ios animation

我正在使用EGOTableViewPullRefresh来获取tableView中的提升效果。我添加了UIBarButtonItem (IBAction)refreshBtnClicke,可以在 EGORefreshTableHeaderView.h 中调用自定义方法refreshByClickRegreshBtn:来显示EGORefreshTableHeaderView并重新加载tableView 1}}

TableViewController.m

-(IBAction)refreshBtnClicked{

    [_refreshHeaderView refreshByClickRegreshBtn:self.tableView];

}

EGORefreshTableHeaderView.h

- (void)refreshByClickRegreshBtn:(UIScrollView *)scrollView{

[self setState:EGOOPullRefreshLoading];
NSLog(@"scrollView.contentInset.top :%f", scrollView.contentInset.top);// it's always 0 here
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
[scrollView setContentInset:UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f)];

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

问题:如果tableView中没有数据,EGORefreshTableHeaderView将始终在UIBarButtonItem点击后显示。但是,一旦下载的数据填满tableView,即使EGORefreshTableHeaderView被调用,我再次点击UIBarButtonItem也不会出现refreshByClickRegreshBtn:。任何帮助表示赞赏:)

1 个答案:

答案 0 :(得分:1)

通过将[scrollView setContentInset:UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f)]替换为[scrollView setContentOffset:CGPointMake(0, -60)]来解决问题。

- (void)refreshByClickRegreshBtn:(UIScrollView *)scrollView{

[self setState:EGOOPullRefreshLoading];
NSLog(@"scrollView.contentInset.top :%f", scrollView.contentInset.top);// it's always 0 here
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
//[scrollView setContentInset:UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f)];
[scrollView setContentOffset:CGPointMake(0, -60)];

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