search

Home  >  Q&A  >  body text

ios - 如何才能让tableview的headerview以及footerview不随着tableview滚动

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

天蓬老师天蓬老师2773 days ago725

reply all(5)I'll reply

  • 怪我咯

    怪我咯2017-04-17 13:45:40

    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.

    reply
    0
  • PHPz

    PHPz2017-04-17 13:45:40

    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.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:45:40

    Just put it on the view.

    reply
    0
  • 黄舟

    黄舟2017-04-17 13:45:40

    -(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);
        }
    }

    }

    reply
    0
  • 迷茫

    迷茫2017-04-17 13:45:40

    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)

    reply
    0
  • Cancelreply