ios – 在新的Storyboard中将值传递给UIViewController – Swift

ios – 在新的Storyboard中将值传递给UIViewController – Swift,第1张

概述我试图将值传递给新的视图控制器 – 位于新的故事板文件中.但是当我这样做时,我从NewViewController得到的结果总是为零. 下面是我在新故事板中显示视图控制器的方法: // Show create account page with custom transitionvar storyboard : UIStoryboard = UIStoryboard(name: Storyboa 我试图将值传递给新的视图控制器 – 位于新的故事板文件中.但是当我这样做时,我从NewVIEwController得到的结果总是为零.

下面是我在新故事板中显示视图控制器的方法:

// Show create account page with custom Transitionvar storyboard : UIStoryboard = UIStoryboard(name: Storyboardname,bundle: nil)var vc : UIVIEwController = storyboard.instantiateVIEwControllerWithIDentifIEr(NewVIEwController) as UIVIEwController

我尝试在这里发送信息:

// Pass the delegate to the first vIEw controllerlet newVIEwController:NewVIEwController = NewVIEwController()newVIEwController.createAccountDelegate = selfnewVIEwController.teststring = "hello"

然后呈现视图控制器.

vc.TransitioningDelegate = selfvc.modalTransitionStyle = UIModalTransitionStyle.CoverVerticalself.presentVIEwController(vc,animated: true,completion: nil)

这是我的NewVIEwController,我尝试接收值.但最终仍然是零.

import UIKitclass NewVIEwController: UIVIEwController {    var createAccountDelegate:AccountCreationDelegate!    var teststring:Nsstring!    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()    }

我错误地发送了这些值吗?

解决方法 您正在使用此行创建NewVIEwController的新实例
let newVIEwController:NewVIEwController = NewVIEwController()

而是将变量和委托分配给已从StoryBoard实例化的vc

var storyboard : UIStoryboard = UIStoryboard(name: Storyboardname,bundle: nil)// It is instance of  `NewVIEwController` from storyboard var vc : NewVIEwController = storyboard.instantiateVIEwControllerWithIDentifIEr(NewVIEwController) as NewVIEwController// Pass delegate and variable to vc which is NewVIEwControllervc.createAccountDelegate = selfvc.teststring = "hello"vc.TransitioningDelegate = selfvc.modalTransitionStyle = UIModalTransitionStyle.CoverVerticalself.presentVIEwController(vc,completion: nil)
总结

以上是内存溢出为你收集整理的ios – 在新的Storyboard中将值传递给UIViewController – Swift全部内容,希望文章能够帮你解决ios – 在新的Storyboard中将值传递给UIViewController – Swift所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1101152.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存