UITextField text field not set

I am trying to update a username field for a text field. Currently, there is an owner of the place that says "Username". I am loading the username from the settings file, but for clarity, I just specify it in the username.

- (void)viewDidLoad { settings=[Settings new]; [settings loadData]; //username.text=settings.username; username.text=@ "Test"; } 

For some reason this does not work !!! However, if I have a button that when I click on it will update the text box.

eg.

 - (IBAction)login:(id)sender{ username.text=@ "test"; } 

Thus, the button updates the text, but I cannot update it from viewDidLoad. Is this a problem with threads? I can’t believe it is that simple for so long.

+4
source share
3 answers

Controls are probably not created at this point.

Try setting the value to - (void) viewDidAppear: (BOOL) animated in your ViewController.

You can also try - (void) viewWillAppear: (BOOL) animated .

+9
source

I don’t know why, but you can change the text of the text field AFTER it was originally displayed

=> use - (void)viewDidAppear:(BOOL)animated

it will work

+3
source

You declared the text field as an IBOutlet inside the property. The error I made was that I forgot to connect the output (text fields) to the file owner in Interface Builder.

0
source

All Articles