我尝试在viewControllers之间传递值。但问题是,价值总是零。
在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
,但我认为概念应该是相同的。
答案 0 :(得分:4)
在创建对话框之前设置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)