swift - found nil while unwrapping an Optional value when try to hidden navigation bar -


i have problem. want make if cell tapped on 1st table view, display 2nd view controller , navigation bar hidden. go 1st view controller using button code:

@ibaction func backbuttontapped(sender: anyobject) {     let storyboard: uistoryboard = uistoryboard(name: "main", bundle: nil)     let vc: uiviewcontroller = storyboard.instantiateviewcontrollerwithidentifier("restaurant")     self.presentviewcontroller(vc, animated: true, completion: nil) } 

but print out

fatal error: unexpectedly found nil while unwrapping optional value 

in 2nd view controller, hidden navigation bar using this:

    func hiddennavbar(){      self.navigationcontroller!.navigationbar.hidden = true } 

and show navigation bar again on 1st view controller using :

override func viewwillappear(animated: bool) {     createnavbar() }  func createnavbar(){      self.navigationcontroller!.navigationbar.hidden = false } 

my main storyboard looks this: enter image description here

you using wrong way go previous view controller. if using navigation view controller push second view controller need pop view controller using self.navigationcontroller?.popviewcontrolleranimated(true)

how uinavigationviewcontroller works? creates stack keep track of view controllers push why if want go back, need pop view controller top stack works.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -