-3

I'm trying to show the ToolBar of the navigationcontroller after pushing from a Objective C Class to a Swift Class by using this code, but the toolbar is not shown:

self.navigationController?.setToolbarHidden(false, animated: false)

Then I did a print of self.navigationController? and it returned nil.

If I go from Obj-C to Obj-C the navigationController is found.

Any solutions?

fisher
  • 1,286
  • 16
  • 29
  • 1
    You're misunderstanding the problem. This has nothing to do with language. If `self.navigationController` is nil, then this view controller instance's view is _not_ in a navigation interface - plain and simple. – matt Dec 30 '14 at 16:21
  • Well, that's what I thought. But the viewcontroller is included in the storyboard the same way as my other viewcontrollers, however this one is has its class written in swift. It works perfectly fine, but as I mentioned I am not able to show the toolbar. However, if I select the navigation controller in storyboard and turn on toolbar from interface builder, the toolbar is showing.. – fisher Dec 30 '14 at 18:55
  • Believe me, the runtime knows more than you do. If you want help understanding what is going on, you must give information about what is going on. Where _is_ this code? When is it called? How does this view controller get pushed? And so on. – matt Dec 30 '14 at 19:05
  • I'm sorry for the bad question. Not my intention. Just frustrated. Apparently, if I call for the navigationController in viewDidAppear() it works fine. In viewDidLoad() it returned nil. – fisher Dec 30 '14 at 19:52
  • 1
    Exactly what I suspected. That is why I was trying to get you to tell me where it was called. But the way to ask a question is to _give_ information. Do not _hide_ information and rely on others to guess. Congrats, though, on solving it yourself! Well done. You can even give that as your own answer (and you can accept it, in 48 hours). The lesson here, I hope, is: Believe the runtime! It knows more than you do... – matt Dec 30 '14 at 19:59

1 Answers1

5

If I call for the navigationController in viewDidAppear() it works fine. My problem was that I called for it in viewDidLoad() and it returned nil.

fisher
  • 1,286
  • 16
  • 29