Swift 3.2
1. Create New Project
2. Single View without core data
3. Click on MainStoryBoard
4. On main ViewController - Add 1 button and 1 textfield
5. Now, Add new View Controller file - ViewTwo
(Right click on main project --> New File --> Choose Swift --> and type name "ViewTwo" --> create ). SEE IMAGEs
6. Inside the ViewTwo class file write this code.
ViewTwo.swift
//
// ViewTwo.swift
// ShowView1
//
// Created by Divakar Singh on 4/3/17.
// Copyright © 2017 Divakar Singh. All rights reserved.
//
import Foundation
import UIKit
class ViewTwo : UIViewController {
@IBOutlet var Label: UILabel!
var LabelText = String()
override func viewDidLoad() {
Label.text = LabelText
}
}
7. Inside the ViewController class file write this code
ViewController.swift
//
// ViewController.swift
// ShowView1
//
// Created by Divakar Singh on 4/3/17.
// Copyright © 2017 Divakar Singh. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet var TextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
var DestViewController : ViewTwo = segue.destination as! ViewTwo
DestViewController.LabelText = TextField.text!
}
}
No comments:
Post a Comment