0

So i have two View Controllers, Vc1 and Vc2. I am navigating from Vc1 to Vc2 by using the following:

 let vc2 = Vc2(nibName: "Vc2", bundle: nil)
 self.navigationController?.pushViewController(vc2, animated: true)

then in Vc2 I do:

 self.navigationController?.popViewControllerAnimated(true) 

Now how can I access a method defined in Vc1 from Vc2? Note: I am not using storyboards instead i am using Xib files.

pogbamessi
  • 311
  • 3
  • 17
  • What, exactly, do you want to do? Why do you want to access a method in another view controller? I suspect there's a better way to do this, but we'd need to know what your goal is. – Undo Nov 10 '15 at 15:29
  • You can try NSNotificationCenter, http://stackoverflow.com/questions/33299670/how-to-pass-data-between-uicollectionviewlayout-and-uiviewcontroller/33304893#33304893 – Dan Beaulieu Nov 10 '15 at 16:30

1 Answers1

0

You have to keep a reference of Vc1 in Vc2 then do something like this :

 let vc2 = Vc2(nibName: "Vc2", bundle: nil)
 vc2.vc1 = self
 self.navigationController?.pushViewController(vc2, animated: true)

Then you'll be able to call methods of Vc1 on self.vc1 in Vc2

dosdos
  • 1,519
  • 1
  • 10
  • 14