rodrigoalvesvieira
rodrigoalvesvieira

Reputation: 8062

prepareForSegue can't get the destination view controller on iOS 7

I have to write an iOS app that supports both iOS 7 and 8 and in this app I have two view controllers A and B with navigation controllers and a segue between them. When the segue activates, I have to fetch data from the view controller A to the view controller B. My code works perfectly on iOS 8 but not on iOS 7.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.

    if segue.identifier == userDataSegue {
        let navController = segue.destinationViewController as? UINavigationController

        if let userDataTableViewController = navController?.topViewController as? UserDataTableViewController {
            userDataTableViewController.userData = user
        }
    }
}

Do you know why does this happen and how can I fix it? I could "work around" the problem by saving stuff in NSUserDefaults and reading it in the vc B but that would make my code a mess.

I appreciate any help :D

Upvotes: 0

Views: 5491

Answers (1)

Jen Jose
Jen Jose

Reputation: 4035

Don't forget to create a public property userData in Second ViewController.

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) 
{
if (segue.identifier == "segueTest") {
var svc = segue!.destinationViewController as secondViewController;

svc.userData = user

}
}

Upvotes: 2

Related Questions