我有两个视图控制器,当我按下确定按钮时,我希望将数据从第一个视图传递到第二个视图,当我按下取消时,移动到第二个视图而不传递任何数据
我写了这段代码
@IBAction func submitL() {
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
var third = segue.destinationViewController as ViewController
third.lastName = theLastName.text
third.name = theName.text
}
}
此代码无效
答案 0 :(得分:1)
从初学者的提交功能中取出prepareForSegue()方法。在那之后查找“performSegueWithIdentifier”,你会看到这一切是如何工作的。
self.performSegueWithIdentifier("nameOfYourSegue", sender: self)