class SecondViewController: UIViewController {
@IBOutlet weak var myNameTextField: UITextField!
@IBOutlet var myNameLabel: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func onSubmitClick(_ sender: Any) {
if(myNameTextField.text != ""){
myNameLabel.text=myNameTextField.text
}
}
You are probably new to the forum. When you paste code, please use Paste and Match Style,
then use Code formatter tool (<>)
class SecondViewController: UIViewController {
@IBOutlet weak var myNameTextField: UITextField!
@IBOutlet var myNameLabel: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func onSubmitClick(_ sender: Any) {
if(myNameTextField.text != "") {
myNameLabel.text = myNameTextField.text
}
}
You declared myNameLabel as UIView
Most likely, you need a UILabel:
@IBOutlet var myNameLabel: UILabel!
To change:
- first disconnect the label in Storyboard from its IBOutlet (right-click on the label in storyboard, then click the small x in front of Referencing outlet)
- change in code UIView to UILabel
- reconnect the label to its IBOutlet
- do a clean Build Folder (Product Menu) to clean evrything
That should work now.
If that do not work, please tell exactly what error you get. If that works, don't forget to close the thread by marking the correct answer.