1

I want to create a fixed header that doesn't scroll with tableViewCells, or other content that I have. The header should stay in place fixed, just like in most iOS apps.

Here is the image of the issue I'm facing:

enter image description here

I tried embedding it in a NavigationController & a TabViewController. That didn't work.

I also tried adding a scroll-view.

I referred to this link but it's outdated and didn't help: how iphone facebook app make the navigation bar fixed

Thanks.

Community
  • 1
  • 1
Lukesivi
  • 2,206
  • 4
  • 25
  • 43
  • 1
    Well a `UINavigationController` adds a system navbar, which in fact is fixed in place. How did you use it and what went wrong then? Are you using storyboards? Was your navigation controller an initial view controller? – Losiowaty Nov 02 '15 at 14:53
  • Using the UINavigationController I can't edit the nav bar, add an image nor change the color. I can only change the text. Now I tested it using a new UINavigationController. The Navigation Controller is the initial view controller. I can't edit it in the storyboard though. At the moment, I'm using a ViewController with a nav bar, which looks like the image I posted in the question. – Lukesivi Nov 02 '15 at 15:00
  • Of course you can! To change it's color : http://stackoverflow.com/questions/17014713/how-to-change-uinavigationbar-background-color-from-the-app-delegate and to change the text tile to an image (or other arbitrary view) : http://stackoverflow.com/questions/8814056/how-to-add-image-in-uinavigationbar-in-iphone-app – Losiowaty Nov 02 '15 at 15:03
  • Thanks. So I should code it? I don't mind, but is there any way to do it in the storyboard? – Lukesivi Nov 02 '15 at 15:04
  • You can change the color in storyboard, but I don't think you can add an image though. To change color in storyboard, please refer the image : http://i.imgur.com/tZu9JlH.png – Losiowaty Nov 02 '15 at 15:11
  • That isn't appearing for me, which is strange... I was able to do that on the VC nav bar, but not on the navigation controller... Weird. I'll change it with code. Thanks! – Lukesivi Nov 02 '15 at 15:16

1 Answers1

2

I'd really recommend fooling around with the Navigation controller until you figure it out, it's really the best method for this. If you've embedded it, I'd check out your view with the Attributes inspector, to make sure everything needed is enabled.

HOWEVER, there is another way I've used before. Create a new ViewController, and create two views inside of it. One will be your FakeNavBar, and the other will be a container/TableView that'll hold your data.

Once you've added both these to your new VC, just set them up normally, and bingo! One tip for this, is that NavBar is typically 64 points high, so your fake bar will be something like this:

fakeNavBar.frame = CGRectMake(0, 0, theWidth, 64)
tableView.frame = CGRectMake(0, 64, theWidth, theHeight-64)

And your view hierarchy will look like this: enter image description here

MQLN
  • 2,292
  • 2
  • 18
  • 33
  • Interesting... Will try this. – Lukesivi Nov 02 '15 at 15:03
  • It works petty well when a NavBar just doesn't cut it, lemme know if you need any more info. – MQLN Nov 02 '15 at 15:04
  • Running through some issues. When I embed the viewController the cell moves up like this: http://postimg.org/image/r90dnesvl/ + http://postimg.org/image/a9ix9yffd/ and when I set it higher (for some reason I can't find the constraint that let me make the cell lower) the cell is still out of place and is too high. – Lukesivi Nov 02 '15 at 15:21
  • Also, i should create a ViewController, and not a Navigation Controller? – Lukesivi Nov 02 '15 at 15:23
  • Well they're two methods I described in my answer that could help you reach your goals: 1 would be to embedding a Navigation Controller (but you shouldn't need to create a new page for that), and 2 is to make a new ViewController, and put your tableview and a create a FAKE navigation controller out of a UIView (and then add buttons/formatting/etc to it). Does this make sense? – MQLN Nov 02 '15 at 15:27
  • Got it working. Amazing hack. PS, great bio. Same story. – Lukesivi Nov 02 '15 at 15:31