0

So Im very new to coding, but I'm trying to make a simple text field where you can enter password, and if that password/string is equal to the password I have set, it will do a action.. here is what I have so far, but it dose not work

 @IBOutlet weak var KodeText: UITextField!
@IBOutlet weak var enterknapp: UIButton!

var password = "123"




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

    enterknapp.isEnabled = false

    if password == KodeText.text { enterknapp.isEnabled = true
}

}

BlondePK
  • 7
  • 1
  • 6
  • Have you checked with a breakpoint that *enterknapp.isEnabled = true* is being executed? – Oxthor Nov 27 '17 at 11:50
  • Compare password in "shouldChangeCharactersIn" of UITextFieldDelegate function or Click event of UIButton(enterknapp), not in viewDidLoad. – Jay Patel Nov 27 '17 at 11:59

1 Answers1

0

The reason this doesn't work is because you call it from the viewDidLoad method. In the application lifecycle a bunch of built in methods get called in a particular order and if you override them you can perform things you need. In your case the viewDidLoad gets executed when the viewController is loaded from nib. At this time you do not have anything in the kodeText (please use lowercase for property names).

You either set up another button and create an action (not an outlet like for enterknapp and you do your code there or you implement the TextFieldDelegate protocol to check for changes.

Andras M.
  • 838
  • 7
  • 12