viewController間で値を渡そうとしました。しかし問題は、値が常にゼロであることです。 firstVCで値が渡されても値を渡すとnilを返す
私が行います
// 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)
そしてsecondVC中:
var selectedTestString: String! //Unwrapping because I know value does exist
override func viewDidLoad() {
super.viewDidLoad()
print(selectedTestString) //Gives nil
}
私は.xib
でそれを最初にやっているが、私はコンセプトは同じであるべきだと思います。
obj-cに弱いものがありますか? – SeanChense
'rating 'を' let'から 'var'にしてみることができますか?それは参照ではない(rating of Functional Programming nature of swift) 'ratingVC'のコピーを使って何かをしなければならないかもしれません。 'popup'を作成する前に値を設定することをお勧めします。 – MjZac