Search code examples
iosswiftviewwillappear

viewDidAppear from specific view controller


I am looking to have some code run when my view controller appears from a specific, other view controller. Something along the lines of this pseudo code:

override func viewWillAppear(animated: Bool) {

    if appearedFromVC == specificVC {
        println("appeared from specificVC")
    }
}

Solution

  • You can set a BOOL value like var isFromSpecificVC: Bool for the specificVC, and in your appedaredFromVC make something like :

    if speicificVC.isFromSpecificVC == true {
    }
    

    Also you can add a NSNotification in appedaredFromVC,

    NSNotificationCenter.defaultCenter().addObserver(self, selector: "method:", name: "from_specific_view_controller", object: nil)
    

    and post this notification when specificVC disappear. Good luck : )