How do I segue values when my ViewController is embedded in an UINavigationController?

百般思念 提交于 2019-12-01 07:32:44

问题


I have two view controllers that send values back and forth via segues and the prepareForSegue method. This has been working out perfectly for me until I decided to embed my ViewController inside a Navigation Controller.

If you look at the method below you can see the problem is that my destinationViewController is no longer ViewController... its my newly created UINavigationController.

TimeViewController.swift (secondary controller)

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        var dest = segue.destinationViewController as! ViewController
        var min = selectedMinute * 60
        output = min + selectedSecond

        dest.returnedLabel = recievedString

        if cancelled == true {
            dest.returnedValue = 0
        } else {
            dest.returnedValue = output
        }

    }

Once my ViewController is embedded in the UINavigationController I get this error:

Could not cast value of type 'UINavigationController' (0x1088ff698) to 'deleteCoreData.ViewController' (0x106a1f9b0).

So, if I cast my destinationViewController as a UINavigationController I rightfully lose access to the variables that I had previously. These variables are how I persist the data between the controllers.

So my question is:

How do I segue values when my ViewController is embedded in an UINavigationController?

Update: This is what my storyboard looks like...


回答1:


casting it as ViewController is working fine for me.

var dest = segue.destinationViewController as! ViewController

And your segue connection should be :



来源:https://stackoverflow.com/questions/29641325/how-do-i-segue-values-when-my-viewcontroller-is-embedded-in-an-uinavigationcontr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!