0

The text below here uses a uitextield and saves it to a label. Lets say this is view controller A.

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var text: UITextField!
@IBOutlet weak var labelz: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

}


   @IBAction func ritaOra(_ sender: Any) {
    labelz.text = text.text
    UserDefaults.standard.set(labelz.text, forKey: "myName")
    text.text = ""

}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
if let x = UserDefaults.standard.object(forKey: "myName") as? String
{
    labelz.text = x

    }
}

This code below is what I use in a camera. Lets say this is view controller b.

let text = "Python"
let label = UILabel(frame: CGRect(x: 125, y: 400, width: self.view.frame.width, height: 300))
 label.font = UIFont(name: label.font.fontName, size: 122)

 label.textColor = UIColor.blue
 label.alpha = 0.3
 label.text = text

How can I take the textview in view controller a and place into where let text = "Python" (in view controller b) is currently.

1 Answers1

0

How are you navigating from ViewController A -> B?

If you're using a Storyboard Segue, you'll want to look into prepareForSegue(). It is called when a segue is started, and gives you a place to set variables on the ViewController you are segueing to (referred to as the destination). Inside prepareForSegue you would simply set the variable on the destination ViewController.

See this answer for an example: https://stackoverflow.com/a/40394037/1575489

Community
  • 1
  • 1
Austin
  • 1,369
  • 1
  • 13
  • 19