0

This is my code in VC1

I have this var user = User() in VC1 that has all the data.

func handleMessageView() {
            let layout = UICollectionViewFlowLayout()
            let messageViewController = MessageViewController(collectionViewLayout: layout)
            messageViewController.user = user
            let messageNavController = UINavigationController(rootViewController: messageViewController)
            self.present(messageNavController, animated: true, completion: nil)
        }

This is called by a UIBarbutton.

in VC2 I just have a recieving var. var user = User() This var is returning a nil, Im not using storyboard nor xib. This is all programmatic.

CRey
  • 1,150
  • 2
  • 9
  • 21
  • 1
    let viewController = self.storyboard.instantiateViewControllerWithIdentifier("ansView") as AnsViewController viewController.num = theNum self.presentViewController(viewController, animated: true, completion: nil) – Sharda Prasad May 25 '17 at 06:54
  • Im not using storyboard. did this work for you without storyboard? I've tried this and its crashing. – CRey May 25 '17 at 07:25
  • 1
    Are you passing data programmatically ? – Sharda Prasad May 25 '17 at 07:27
  • 1
    **Use This** let controller = ECCancelAppointmentView() messageViewController.user = user controller.customDelegate = self self.navigationController?.pushViewController(controller, animated: true) – Sharda Prasad May 25 '17 at 07:29
  • Yes I am passing data programmatically. Can you show me what `customDelegate` is in your VC2 or can you explain what kind of variable that is? – CRey May 25 '17 at 07:58
  • 1
    i am using this delegate for other user like button action or any data update. let controller = ECCancelAppointmentView() messageViewController.user = user self.navigationController?.pushViewController(controller, animated: true) **you can user this i am passing model object but you can pass any thing like int, NSString or array etc.** – Sharda Prasad May 25 '17 at 08:06
  • Yeah, I understand what you mean now. I added a `var vc1: VC1?` inside VC2 so I can use it as `vc2.vc1 = self` inside my function but its still returning a nil. I dont understand what Im doing wrong. I am also passing a model. – CRey May 25 '17 at 08:20
  • 1
    If you eable to send code with me then I check your problum. – Sharda Prasad May 25 '17 at 10:00
  • https://github.com/CeriOSR/Cerios-Tracker my codes are here in the Template branch. So basically, Im trying to pass user data from RootViewController all the way to MessageViewController, passing through TrackerViewController. codes might be messy. I haven't refactored and Im still messing around with this Message feature. – CRey May 25 '17 at 16:43
  • Thanks for you help @ShardaPrasad. I solved it. The issue was I was presenting a TabBarController but I was passing the data to TrackerController which is a VC inside the TabBarController. What I had to do was pass the data to TabBarController and pass it to the different VCs, if needed, inside the tabBar from the TabBarController. – CRey May 25 '17 at 23:10

0 Answers0