当我的 ViewController 嵌入到 UINavigationController 中时,如何转义值? [英] How do I segue values when my ViewController is embedded in an UINavigationController?

查看:20
本文介绍了当我的 ViewController 嵌入到 UINavigationController 中时,如何转义值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个视图控制器,它们通过 segue 和 prepareForSegue 方法来回发送值.在我决定将我的 ViewController 嵌入到导航控制器中之前,这对我来说一直是完美的.

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.

如果您查看下面的方法,您会发现问题在于我的 destinationViewController 不再是 ViewController...它是我新创建的 UINavigationController.

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(二级控制器)

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
        }

    }

一旦我的 ViewController 嵌入到 UINavigationController 中,我就会收到此错误:

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

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

因此,如果我将 destinationViewController 转换为 UINavigationController,我理所当然地无法访问我以前拥有的变量.这些变量是我在控制器之间保存数据的方式.

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.

当我的 ViewController 嵌入到 UINavigationController 中时,如何转义值?

更新:这就是我的故事板的样子...

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

推荐答案

将其转换为 ViewController 对我来说效果很好.

casting it as ViewController is working fine for me.

var dest = segue.destinationViewController as! ViewController

你的转接连接应该是:

这篇关于当我的 ViewController 嵌入到 UINavigationController 中时,如何转义值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆