I have made a simple project which sends data from one view controller to a second.
It works for a string, but I now want to change the code so it can multiply the UITextField answer by 10 and output it to the label in the Second ViewController. I know that I just need to change the string to Int but I've tried lots of things and nothing has worked.
I know there must be some simple way that I'm overlooking.
Any help is appreciated.
ViewController
import UIKit
class ViewController: UIViewController {
@IBOutlet var EnterNumber: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
EnterNumber.delegate = self
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let VC2 : ViewController2 = segue.destination as! ViewController2
VC2.LabelText = EnterNumber.text!
}
}
extension ViewController : UITextFieldDelegate{
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}
ViewController 2
import UIKit
class ViewController2: UIViewController {
@IBOutlet var Label: UILabel!
var LabelText = String()
override func viewDidLoad() {
super.viewDidLoad()
Label.text = LabelText
}
}