我正在开发一个 swift 应用程序,我已经使用 presentViewController
创建了指向其他 View 的链接,但我不知道如何传递变量。如何将变量传递给新 View ?
@IBAction func WorkoutPressed(sender: AnyObject) {
let storyBoard = UIStoryboard(name: "Main", bundle:nil)
let workoutView = storyBoard.instantiateViewControllerWithIdentifier("workoutView") as WorkoutViewController
self.presentViewController(workoutView, animated: false, completion: nil)
//self.navigationController?.pushViewController(workoutView, animated: true)
}
谢谢
最佳答案
这比您想象的要容易:您不需要传递参数,因为您可以直接访问下一个 View Controller 的类变量。
也就是说,你可以这样做:
workoutView.myVar = myVal
并且,当该 View 加载时,myVar
将具有值 myVal
。 (不过不要忘记在 WorkoutViewController
中声明它)。
关于swift - 在 Swift 中使用 PresentViewController 传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27326870/