I know that this question has been asked quite many times but I am damn tired of searching for this error but couldn't make it.
I have a scenario in which I am moving from one viewController to another i.e (VC1->VC2). I am using NSNotificationCenter to pass some data to the other VC.
VC1 -
@IBAction func sendNotfctn(sender: AnyObject)
{
NSNotificationCenter.defaultCenter().postNotificationName("MY NOTIFICATION", object: self)
performSegueWithIdentifier("Go", sender: self)//Here I move to VC2.
}
VC2
override func viewDidLoad()
{
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "actOnMyNotification:", name: "MY NOTIFICATION", object: nil)
// Do any additional setup after loading the view.
}
func actOnMyNotification(notification:NSNotification)
{
print("I recived the notification!")
}
But my selector method is not called. What problem or what error am I making?
Version used - XCode 7.2, SWIFT - 2.1.1
Update -
I have VC1 - VC2(embedded in navigation controller). The segue i am using is connected from VC1 to Navigation controller of VC2. So I can't use segue passing for that.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "Go"
{
let destVC = segue.destinationViewController as! VC1//this line is not possible for my above said case
}
}
If any alternatives please suggest.
prepareforsegue
to send data or can use delegates and protocol – Ketan Parmar