I have a UITableView and a small custom view. I want the custom to stay below the navigation bar, but above the tableview. So when the custom view moves up and down, it looks like that the custom view pops out from navigation bar’s back.
At first I make the custom view the subview of the tableview and everything seems fine. But when the tableview is scrolled, the position of the custom view is also changed, which is not what i want.
Then i made the navigation bar the superview, but now the custom view stays above the navigation bar. And i don’t know how to change the z-order between parent view and subview.
So can anybody give me some advice?
Thank you!
Depending on how you create your view hierarchy – insert it either above the table view or bellow navigation bar:
There’s also an option to insert your subview at certain index. So if your navigation bar is topmost (i.e. at index 0) and table view is bottommost (i.e. index of
[[[[self view] subviews] count] - 1]) you can insert your custom view in-between like this:This way your table view will descend by one level in its superview and “layering” of subviews will be following:
Beware though that putting your custom subview into standard superview you’d have to maintain the position yourself as it won’t be scrolling together with the tableview as before.