-
Notifications
You must be signed in to change notification settings - Fork 0
pass data from ViewControllers to another ViewController 2
Mohammad Azmal Hossain edited this page Feb 7, 2017
·
1 revision
-
take two viewController with class. next give identifier segue name of button which segue will be passed values.
-
first class
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var textHere: UITextField!
var saveText: String!
@IBAction func nextButton(_ sender: AnyObject) {
saveText = textHere.text! self.performSegue(withIdentifier: "showSegue", sender: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showSegue" {
let destination = segue.destination as! SecondViewController
destination.myText = saveText } }
override func viewDidLoad() {
super.viewDidLoad()
} }
-
second class
import UIKit
class SecondViewController: UIViewController {
var myText: String! = nil
@IBOutlet weak var previewLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
previewLabel.text = myText
} }