-1

I have a main page, which has a button that will go to another page.

I want when i go the second page, to have a back button at the top left of the navigation bar.

I added a navigation controller to the main view controller, and then i added a push segue to my second view controller (second page), so an automatic back button created.

what i want is that i do NOT want the navigation bar to be in the main view controller, and I don't want it to be in the second view controller, I just want to have the back button in the second view controller.

I thought about it and i came up doing:

self.navigationController?.setNavigationBarHidden(true, animated: false)

in the main view controller, that actually hide the navigation, but that makes the second view ctonroller to loose its back button.

do you have any solution to my problem?

this is the main view controller (which has the navigation bar, but i would like to not have it)

enter image description here

this is the second view controller, which has the back button, enter image description here

I have no problem if i leave the navigatino bar, if it was transparent, any idea please? (and by transparent, i mean i can see my image bellow it)

Update 1

after the first comment gives me a hint, i tried to applied it like this:

class CustomNavigationBar: UINavigationBar {
    override func drawRect(rect: CGRect) {
        super.drawRect(rect)
    }
}

and I set the class of my navigation bar in the UINavigationControlelr to my custom navigation bar. and in my main view controlelr i add this:

self.navigationController?.navigationBar.translucent = true;
self.navigationController?.navigationBar.backgroundColor = UIColor.clearColor()

but the result is that my Main view controller, still has a place (though it is empty) for the navigation bar. can't i make this place as transparent to see the image bellow it?

sarah
  • 1,201
  • 1
  • 9
  • 29
  • See this for some ideas - http://stackoverflow.com/questions/13431976/visible-buttons-with-transparent-navigation-bar – Paulw11 Nov 27 '15 at 00:18
  • @Paulw11 please check my updated answer, i read your suggestions and i added what i did – sarah Nov 27 '15 at 00:33
  • @Paulw11 is it possible that i already did it correct, but the image does't go bellow the navigation bar? that is why i see it as white empty space ? – sarah Nov 27 '15 at 00:37
  • @Paulw11 plus can I infer that because i set the navigation bar to my custom class inthe ui navigation controller, then all the view controllers that I navigate to, from my main view controller will have this custom navigation bar ? – sarah Nov 27 '15 at 00:39
  • Possibly. Have you set the view to extend under top bars? How is your image view constrained?. The UINavigationController is the containing view controller; it doesn't change as you push and pop view controllers – Paulw11 Nov 27 '15 at 00:40
  • the thing is that i make a constrain from my image to the `Top Layout ` by zero. the issue is that because the naviation bar is there, this `Top Layout` is not on the top of the screen. you got me? (or i make a picture for u) sorry my english sucks – sarah Nov 27 '15 at 00:46
  • Delete your top constraint then ctrl-drag from your image to the top of the scene. When you release the mouse button press alt and select "top space to container margin" from the pop-up and then edit this constraint to make sure the value is 0 – Paulw11 Nov 27 '15 at 00:51
  • @Paulw11 OMG OMG OMG OMG OMG OMG OMG OMG OMG OMG OMGO MGOM OMG OMG OMG OMG i am so lucky to have you, thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you, thank you, thank you, thank you, – sarah Nov 27 '15 at 00:58
  • @Paulw11 last thing please, you way works great with all view controllers, but with table view controller (that has a header) your way didn't make the header of the table view controller on the header of the screen. do you know why ? – sarah Nov 27 '15 at 01:04
  • Do you mean that the tableview header is below the navigation bar? – Paulw11 Nov 27 '15 at 01:19
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/96303/discussion-between-paulw11-and-sarah). – Paulw11 Nov 27 '15 at 01:23

1 Answers1

4

add this to the main view controller

override func viewDidLoad() {
    super.viewDidLoad()        

    self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)

    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
    self.navigationController?.navigationBar.shadowImage = UIImage()
}

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    self.navigationController?.setNavigationBarHidden(true, animated: true)
}

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)

    self.navigationController?.setNavigationBarHidden(false, animated: true)
}
ZHZ
  • 2,088
  • 13
  • 16
  • you are genious, that solved the first problem, now how an I make the second view controller contains just the back button at the top left ? – sarah Nov 27 '15 at 00:41
  • add this to the viewDidLoad in the main view controller self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: nil, action: nil) – ZHZ Nov 27 '15 at 00:46
  • okay that just removed the text of the back item in the second view controller, however, the navigation bar is still there and it is not transparent, ( i hope you got me, i am talking now about the second view controller ) – sarah Nov 27 '15 at 00:50