开发者

how to make tableView offset become zero?

I have a TableView, that Have so many TableViewCell, but in the end of TableView I want to make a code that will make table开发者_运维知识库view offset become zero, so the tableview back to the top

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (scrollView.contentOffset.y <=-30) {
    [self dosomething];
}
else if(scrollView.contentOffset.y >=1150){
    [tableViewA setContentOffset:CGPointZero animated:YES];//this code is called and yet offset doesn't become 0
}
}

so with this code, if user bounce to the top, it will call dosomething function, and if we bounce to the bottom, it will make a tableViewA at the top, but it's still at bottom. if I am not wrong, the tableView Bounce again to bottom. any one can give me a clue?


I tried your code and find that the tableview did set it's contentOffset to (0,0) but It will continue the drag animation.Seems that during the scroll animation, the tableview animates and changes it's bounds at the same time in order to call layoutSubviews every time the bounds change. So even the contentOffset was set to (0,0) but just after that the bounds was set to a new value to continue the scroll animation.

Maybe you can try

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
    [self setContentOffset:CGPointZero animated:YES];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜