1

hello I have implemented SWRevealViewController in my swift app. The problem I am having is If I set SWRevealViewController as my initial ViewController all works fine. But If I launch this controller through code

 let nav : UINavigationController = UINavigationController(rootViewController: self.storyboard!.instantiateViewControllerWithIdentifier("swrevealviewcontroller") as UIViewController)
 self.navigationController?.presentViewController(nav, animated: true, completion: nil)

the navigation Title and barButtonIcon Disappears which is in my case is a hamburger menu icon.

SWRevealViewController is connected to the HomeViewController. and I am initiating SWRevealViewController when user clicks the login Button.

If you need more information regarding the storyboard screenshot let me know. I'll upload here.

Updated: storyboard

enter image description here

hellosheikh
  • 2,929
  • 8
  • 49
  • 115
  • if you are using `presentViewController` , the `presentViewController` does not embedded with `UINavigationController `.if you want `UInavigation COntroller` in `presentViewController` , implement in customize – Anbu.Karthik Feb 15 '16 at 11:00
  • @Anbu.Karthik then should I use push? – hellosheikh Feb 15 '16 at 11:01
  • 1
    ya if you using `push`, the `UINavigationController` will come , the reason `push` is embedded with `UINavigationController`. – Anbu.Karthik Feb 15 '16 at 11:02
  • @Anbu.Karthik I have done this let nav : UINavigationController = UINavigationController(rootViewController: self.storyboard!.instantiateViewControllerWithIdentifier("swrevealviewcontroller") as UIViewController) self.navigationController?.pushViewController(nav, animated: true) error comes which is 'Pushing a navigation controller is not supported' – hellosheikh Feb 15 '16 at 11:04
  • connect your current viewcontroller embed with `UINavigationController`, then it works, – Anbu.Karthik Feb 15 '16 at 11:05
  • see this link for error bro http://stackoverflow.com/questions/17757072/pushing-a-navigation-controller-is-not-supported – Anbu.Karthik Feb 15 '16 at 11:06
  • you mean I have to embed the swrevealViewcontroller with the navigation controller on the storyboard? am I right ? – hellosheikh Feb 15 '16 at 11:07
  • no I have tried this also then menu doesn't work – hellosheikh Feb 15 '16 at 11:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/103479/discussion-between-hellosheikh-and-anbu-karthik). – hellosheikh Feb 15 '16 at 11:27

2 Answers2

3

navigation controller's navigation bar will only show up for view controllers that are contained by that navigation controller. Here, you're presenting a modal view. It's not contained by the navigation controller.

If you want the navigation bar to continue to appear:

  • If it's purely a matter of style, put a navigation bar on the modal scene you're presenting in the interface builder.
  • If you need to modally present a view that should be contained in a navigation controller, then you need to present a navigation controller--not a view controller.
  • Finally, if the view you're presenting is intended to be part of the navigation controller's navigation stack, then you need to present it with a push, not a modal segue.

Update

Do like simple ,

enter image description here

and call the perform segue as

 [self performSegueWithIdentifier:@"main" sender:self];
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • navigation Bar is appearing but navigation Items on the navigation bar is not appearing – hellosheikh Feb 15 '16 at 11:06
  • are you asking me to upload storyboard screen or mobile app screen ? – hellosheikh Feb 15 '16 at 11:08
  • which viewcontroller you want to navigate – Anbu.Karthik Feb 15 '16 at 11:20
  • @I haven't attached the login screen controller because that is separate and not connected to anything. But login controller has navigationcontroller embeded. so When I click the login button in logincontroller I want to go the homescreencontroller which is you can see on the image – hellosheikh Feb 15 '16 at 11:24
  • Did you understand ? – hellosheikh Feb 15 '16 at 11:26
  • AWESOME.. THANK YOU... Can I have your skype ? – hellosheikh Feb 15 '16 at 11:45
  • ya sure but most of the time I am not used the skype , take my ID , karthik.saral@gmail.com. welcome bro, bye – Anbu.Karthik Feb 15 '16 at 11:46
  • @ Anbu.Karthik One last thing I want to ask.. are you there? – hellosheikh Feb 15 '16 at 11:53
  • okay It works fine somehow.. But In My Main Screen which is before the loginform screen where there is a button of login and register. I am checking on that controller that if user is alreadylogged in or not. If Logged in then I am launching the controller with my same old code that is in my question and same problem comes. what should I do about that ? – hellosheikh Feb 15 '16 at 11:57
  • haha ha , swl is complicated for this concept, ok we go for based on your condition , create the one NSUSerdefault and save when login is successful, then if you terminate the app and reopen time on that `loginform` page on viewdidload chek teh userdefault value is equal or not ,if it is eqaul follow the update answer , else do nothing .. – Anbu.Karthik Feb 15 '16 at 12:01
  • yes I am using nsuserdefault already. I am actually asking the navigation problem. if client is already logged in I am doing this let nav : UINavigationController = UINavigationController(rootViewController: self.storyboard!.instantiateViewControllerWithIdentifier("swrevealviewcontroller") as UIViewController) self.navigationController?.presentViewController(nav, animated: false, completion: nil) – hellosheikh Feb 15 '16 at 12:03
2

I solved my problem by pointing Navigation Controller first and Tab Bar Controller second. Please, see the picture below. Hope this help!..Thanks...

ThetNaing Mizo
  • 4,049
  • 2
  • 14
  • 15