我有两个视图控制器,它们通过 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
你的 segue 连接应该是:
And your segue connection should be :
这篇关于当我的 ViewController 嵌入到 UINavigationController 中时,如何对值进行 segue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!