0

interfa builder flowI am using AKSwiftSlideMenu as basis for an app.

I have a view controller (HomeVC) that is connected to a navigation controller.

If the storyboard entry point is pointing to HomeVC then I get the menu of course, but my app needs to start without the menu and only after certain screens and tasks that are done i want to navigate to HomeVC and allow user access to the menu.

I noticed that if a i place a button on a starting view controller that does not have a connection to the navigation controller, and connect that button directly to the Navigation controller by drag+cntrl then pressing the button will get me from a view controller without a menu to HomeVC and show the menu.

How do i do that programmatically

Thanks in advance for any help

edit: I have tried the following code

    let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let newViewController = storyBoard.instantiateViewController(withIdentifier: "Home") as! UINavigationController
    self.present(newViewController, animated: true, completion: nil)

which did not work resulting with the following err

Could not cast value of type 'myApp.HomeVC' (0x10a159280) to 'UINavigationController' (0x10cc2d3c8).

Johny D Good
  • 427
  • 1
  • 8
  • 26
  • Please give more information on what do you want. If possible share some screens or a flow diagram. Thanks – Shubham Aggarwal May 14 '17 at 11:07
  • hi, added flow diagram. What i want is from start point view controller to get to the view controller where menu is shown, but programatically and not via a button and segue. – Johny D Good May 14 '17 at 11:33

2 Answers2

0
let newViewController = storyBoard.instantiateViewController(withIdentifier: "Home") as! UINavigationController
s

"Home" is not a UINavigationController. Remove as! UINavigationController from this line and the error will go away.

Daniel T.
  • 32,821
  • 6
  • 50
  • 72
  • Hi Daniel, true that removing as! UINavigationController opens HomeVC view controller but without the menu of the navigation controller thus the menu is not seen in view. The same would happen if i had attached start button directly to homeVC and not to the navigation controller. – Johny D Good May 14 '17 at 13:44
  • Then instantiate the navigation controller and present it instead of instantiating the home view controller. – Daniel T. May 14 '17 at 13:46
0

thank you Daniel for telling me to instantiate navigation controller. Ended up giving navigation controller a storyboard id named ccontroller and the following code does what I needed

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewController(withIdentifier: "ccontroller") as! UINavigationController
    self.present(vc, animated: true, completion: nil)
Johny D Good
  • 427
  • 1
  • 8
  • 26