Reputation: 97
I just made a new Swift project, put some text fields and a couple buttons in it, and when I start the app I cannot seem to be able to edit the text fields. Like the text fields are not taking any input. Any of them!
At the moment this is my only code. There should be nothing wrong with it. I literally ran the same code on another app and everything worked perfectly.
@IBOutlet weak var monthlyTF: UITextField!
@IBOutlet weak var annualL: UILabel!
var year = Double()
@IBAction func calculateAnnB(_ sender: UIButton) {
if let monthlyInc = Double(monthlyTF.text!){
year = 12*monthlyInc
annualL.text = "\(year)"
}else{
annualL.text = "That's not a number!"
}
}
There are other buttons and text fields in the app but I have not linked them yet because I didn't get to that part. I just wanted to test it piece by piece. Should I link them all first and then try?
It should be a really simple project. I don't know why I keep getting stuck on stupid technicalities like these.
Upvotes: 0
Views: 2099
Reputation: 56
Try what dinosaysrawr said, and also make sure User Interaction Enabled is set to true in the storyboard (under "View" in the Attributes Inspector).
Upvotes: 1
Reputation: 376
Try deleting and reinstalling the UITextField in the storyboard
Edit: Also, make sure that the textField is enabled in the "Attributes Inspector" under "Control". If it's not enabled, it'll be grayed out and you can't tap on it to edit it
Upvotes: 0