3
    let chatController = ChatLogController()
    chatController.user = user
    let nav: UINavigationController = UINavigationController(rootViewController: chatController)
    self.presentViewController(nav, animated: true, completion: nil)

The code above works, I am trying to pass user, to the next view controller, before presenting However this doesn't work, it gives me nil for user, in the next viewcontroller:

    let chatController = ChatLogController()
    chatController.user = user
   let nav: UINavigationController = UINavigationController(rootViewController: MessagesController())
   // self.presentViewController(nav, animated: true, completion: nil)
    nav.pushViewController(chatController, animated: true)

I really have no idea why, sorry for the dumb questions, I'm very new to this.

slimboy
  • 1,633
  • 2
  • 22
  • 45
  • In your second example, you're instantating a new navigation controller, but that controller is not added to the view controller hierarchy. You have to present it, and only then can you then push anything on it. I also don't quite get why this `MessagesController` is the root view controller of this navigation controller. What is this `MessagesController`? Do you really want to present the navigation controller with both `MessagesController` and `ChatLogController`, or just `ChatLogController`? – Rob Aug 07 '16 at 16:59
  • do you want to use `self.navigationController?.pushViewController(...)` instead? – Sulthan Aug 07 '16 at 18:18

1 Answers1

0

If I am not wrong your problem is MessagesController().

Try this:

let chatController = ChatLogController()
chatController.user = user
let nav: UINavigationController = UINavigationController(rootViewController: chatController)
// self.presentViewController(nav, animated: true, completion: nil)
nav.pushViewController(nav, animated: true)
Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165