【问题标题】:UITableView stick tableHeaderView and sectionHeaderView together on topUITableView 把 tableHeaderView 和 sectionHeaderView 一起粘在上面
【发布时间】:2015-11-19 23:42:58
【问题描述】:

我正在使用普通样式的UITableView 与具有sectionView 的部分。所以,我会将UISearchBar 放在表头视图中,我需要它始终在顶部可见,但在用户向下滚动时保持可滚动行为。

有一张图片是怎样的

所以,滚动时我需要在导航栏和第 2..3..N 部分之间显示HeaderView。标题视图应该坚持导航栏,部分标题视图应该坚持标题视图。

我尝试了以下方法:

@implementation MyTableViewController

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGRect rect = self.tableHeaderView.frame;
    rect.origin.y = MIN(0, self.tableView.contentOffset.y);
    self.tableHeaderView.frame = rect;
}

@implementation MyTableView

-(void)layoutSubviews
{
    [super layoutSubviews];

    CGRect rect = self.tableHeaderView.frame;
    rect.origin.y = MIN(0, self.contentOffset.y);
    self.tableHeaderView.frame = rect;
}

但没有得到任何结果。

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    你,也许不要使用UIScrollViewDelegate

    scrollView.delegate = self
    

    如果你想在 StoryBoard 中使用 scrollView - 将它连接到那里,

    您可以在UITableView 类中充分展示您的代码吗?

    并使用ViewDidLoad!!!

    【讨论】:

      猜你喜欢
      • 2021-10-31
      • 2013-01-20
      • 1970-01-01
      • 2013-10-07
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 2021-08-20
      • 2012-11-11
      相关资源
      最近更新 更多