ios - 如何才能让tableview的headerview以及footerview不随着tableview滚动
天蓬老师
天蓬老师 2017-04-17 13:43:40
0
5
722

tableview的headerview和footer view默认是随着tableview滚动的,现在要求他不随着section滚动,请问我该怎么做呢?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(5)
刘奇

What slides along with the table is the sectionView of the tableview. You can use table.tableFooterView = [[UIView alloc] init...]; so that it will not move as the table moves down.

PHPzhong

Then don’t implement headerView as tableView.
Take headerView as an example, add a section at the front, and then use this headerView as the header of the section. The number of rows in this section is 1 (I heard that there are occasional bugs when it is 0), and the row height is 0, inside cellForRow Just return a cell with the default style.

update: After thinking about it carefully, this can only ensure that this section will not scroll when it is at the top, otherwise it will still scroll out.
The real solution is: instead of placing headerView and footerView in tableView, shorten the height of tableView, place headerView above tableView, and place footerView below tableView.

大家讲道理

Just put it on the view.

黄舟

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

if (scrollView.tag == 100102) {
    UITableView *tableview = (UITableView *)scrollView;
    CGFloat sectionHeaderHeight = TABHEADER;
    CGFloat sectionFooterHeight = 10;
    CGFloat offsetY = tableview.contentOffset.y;
    if (offsetY >= 0 && offsetY <= sectionHeaderHeight)
    {
        tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -sectionFooterHeight, 0);
    }else if (offsetY >= sectionHeaderHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight)
    {
        tableview.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -sectionFooterHeight, 0);
    }else if (offsetY >= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height)
    {
        tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -(tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight), 0);
    }
}

}

迷茫

In fact, if you just want to make a view that does not slide with the tableview, there are two methods
1. Add the view to the NavigationController, so that the view will not slide with the tableview
2. Add the view to the tableview, but Dynamically adjust the coordinates of this view so that its coordinates are always 0. (Involving a small algorithm)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template