1

I am trying to force a navigation bar to show on a modal view. As per this answer, I am trying to do that by embedding just the modal view, nextScreenViewController in a special navigation controller, nextScreenNavigationController.

However, I am using delegate patterns to pass data between the initial viewController and nextScreenViewController. Before embedding in the navigationController, I was initalizing with the following code:

override func prepareForSegue(segue: UIStoryboardSegue, sender:   AnyObject?) {
     if segue.identifier == "goToNextScreen" {      
         let nextScreenDelegate = segue.destinationViewController as! nextScreenViewController
          nextScreenDelegate.delegate = self
     }
}

Some research suggested that, in order to account for nextScreenNavigationController I should use code like...

 override func prepareForSegue(segue: UIStoryboardSegue, sender:   AnyObject?) {
      if segue.identifier == "goToNextScreen" {
          let navigation: UINavigationController = segue.destinationViewController as! nextScreenNavigationController
          var nextScreenDelegate = nextScreenViewController.init()
          nextScreenDelegate = navigation.viewControllers[0] as! nextScreenViewController
          nextScreenDelegate.delegate = self
  }
}

However, that fails without crashing - no data are passed.

Please comment if you want more of my delegate pattern... I just want to be sure it is not a basic implementation problem. Or, is there a better way to show a nav bar on a modal view?

Community
  • 1
  • 1
rocket101
  • 7,369
  • 11
  • 45
  • 64

1 Answers1

0

Sorry - never mind! I realized that the above code works, and my issue was that I failed to assign the navigationController the class nextScreenNavigationController in storyboard.

rocket101
  • 7,369
  • 11
  • 45
  • 64