在导航栏下添加一个粘滞的视图

我已经看到了其他一些例子,但是我没有看到任何真正坚持的东西。 我想要的基本上是一个tableViewHeader。 我有一个导航栏的tableViewController。 我想放置一个视图,在导航栏正下方的小栏中显示一些search条件。 但是当用户滑动查看结果时,我需要粘贴它。

我已经尝试添加一个UIView作为导航栏的子视图,但它总是坐在导航栏的顶部,覆盖一切。

这是什么工作:

// Create a custom navigation view _navigationView = [[UIView alloc] init]; _navigationView.backgroundColor = [UIColor whiteColor]; _navigationView.frame = CGRectMake(0.0f, self.navigationController.navigationBar.frame.origin.y + 44.0f, self.view.frame.size.width, 30.0f); // Create bottom border for the custom navigation view _navigationViewBorder = [[UIView alloc] init]; _navigationViewBorder.backgroundColor = [UIColor darkGrayColor]; _navigationViewBorder.tag = 1; _navigationViewBorder.frame = CGRectMake(0.0f, self.navigationController.navigationBar.frame.origin.y + 74.0f, self.view.frame.size.width, 0.5f); // Add labels for date, results, and the time range _dateDisplay = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 70, 15)]; [_dateDisplay setFont:[UIFont fontWithName:@"HelveticaNeue" size:13]]; [_dateDisplay setText:@""]; _timeRangeDisplay = [[UILabel alloc] initWithFrame:CGRectMake(98, 0, 135, 15)]; [_timeRangeDisplay setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:13]]; [_timeRangeDisplay setText:@""]; _resultsDisplay = [[UILabel alloc] initWithFrame:CGRectMake(240, 0, 80, 15)]; [_resultsDisplay setFont:[UIFont fontWithName:@"HelveticaNeue" size:13]]; [_resultsDisplay setText:@""]; [_navigationView addSubview: _dateDisplay]; [_navigationView addSubview: _timeRangeDisplay]; [_navigationView addSubview: _resultsDisplay]; // Add two views to the navigation bar [self.navigationController.navigationBar.superview insertSubview:_navigationView belowSubview:self.navigationController.navigationBar]; [self.navigationController.navigationBar.superview insertSubview:_navigationViewBorder belowSubview:_navigationView]; 

为什么不把视图添加到你的viewController的视图,并设置它的约束,以便它位于navigationBar正下方,但在tableView上方?

如果只有一些时间,那么可以使其约束动起来以显示/隐藏它。