The first thing you need to do is attach a segue from one view controller to another.
Do NOT attach a segue from a button to a view controller or this will not work.
(Swift 2.2)
class FirstVC: UIViewController {
@IBAction func ToSecondVC(sender: AnyObject) {
let data = "Pass this to next view controller"
performSegueWithIdentifier("ToSecondVCSegue", sender: data)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let secondVc = segue.destinationViewController as! SecondVC
secondVc.data = sender as? String
}
}
class SecondVC: UIViewController {
var data: String?
@IBOutlet weak var dataLabel: UILabel!
override func viewDidLoad() {
dataLabel.text = data
}
}
(Swift 2.2)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.