gpt4 book ai didi

ios - 即使值确实存在,传递值也会返回 nil

转载 作者:行者123 更新时间:2023-11-28 10:16:52 24 4
gpt4 key购买 nike

我尝试在 viewController 之间传递值。但问题是,该值始终为零。

在 firstVC 中我这样做:

// Create a custom view controller
let ratingVC = RatingViewController(nibName: "RatingView", bundle: nil)

// Create the dialog
let popup = PopupDialog(viewController: ratingVC, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true)

ratingVC.selectedTestString = "HELLO"


// Present dialog
self.present(popup, animated: true, completion: nil)

在第二个 VC 中:

var selectedTestString: String! //Unwrapping because I know value does exist

override func viewDidLoad() {
super.viewDidLoad()
print(selectedTestString) //Gives nil

}

我是第一次用 .xib 做,但我认为概念应该是一样的。

最佳答案

在创建对话框之前设置 selectedTestString 的值,这将解决问题。

// Create a custom view controller
let ratingVC = RatingViewController(nibName: "RatingView", bundle: nil)

ratingVC.selectedTestString = "HELLO"

// Create the dialog
let popup = PopupDialog(viewController: ratingVC, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true)

// Present dialog
self.present(popup, animated: true, completion: nil)

关于ios - 即使值确实存在,传递值也会返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40439357/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com