How do I get a reference to UI elements in a storyboard view from the view's controller?

StackOverflow https://stackoverflow.com/questions/18726510

سؤال

I have a button and two text fields on the login screen of an app I'm writing.

UI Situation

When I use the "Go" button on my popup keyboard (or hit enter - it's in the simulator) I have a reference to the UITextField and use it to authenticate my users. It hits this method:

- (IBAction)getPassword:(UITextField *)sender {
[self setPassField:sender];

}

When I use the "Login" button, I am not getting a reference to the password text field and authentication fails every time (empty string is not the password).

Is there a way to get a handle on my fields from my view controller so I do not have to rely on field-driven events to get field references?

هل كانت مفيدة؟

المحلول

You need to create two outlets in your view controller: one for the username text field and one for the password text field. You need to connect the outlets to the fields in your storyboard.

Read “Create Outlets for the Text Field and the Label” in Your First iOS App for Apple's step-by-step instructions on creating and connecting outlets.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top