Add a sticky view underneath the Navigation Bar

I've seen a few other examples, but I haven't seen anything that actually sticks. What I want is essentially what a tableViewHeader does. I have a tableViewController with a navigation bar. I want to put a view into place that shows some search criteria in a small bar directly below the navbar. But I need it to stick when the user swipes to view the results.

I've tried adding a UIView as a subview to the navigation bar, but it always sits at the top of the Navigation Bar, overlaying everything.

Answers


Here's what worked:

// 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];

Need Your Help

How do I convert a “legacy” left outer join statement in Oracle?

sql oracle outer-join

I have two tables (A and G) in an Oracle database that can be joined together based off an account number. The one caveat to this is that one of the tables (G) has about 80 fewer records than the o...

How do I pass a multi-dimensional array of variable size in C?

c arrays multidimensional-array

I'm trying to pass an three dimensional array to a function like this: