0

I have an implementation of class similar to this:

-(id)initWithLogin:(NSString *)_login password:(NSString *)_password{

if(( self = [super init])){

    login = _login;
    password = _password;

}

return self;

}

and my question is - how to init new object with value from TextField (I know how to alloc and init objects, but don't know how to pass values from TextField to this method)?

I'm very beginner of objective-c so every step-by-step solutions will be appreciated (or links for related articles/video tutorial).

4
  • get value from textField in this way: NSString *string = yourTextField.text Commented Nov 20, 2013 at 12:22
  • ok, thank You, can you tell me how/where I can define id/name for TextField (in your example it is yourTextField - where i Can define this value)? Commented Nov 20, 2013 at 12:26
  • where your facing the problem now ? accessing the initWithLogin method are getting the login and password string out side of the method ? Commented Nov 20, 2013 at 12:47
  • please accept any of the answers if your problem get solved else edit your question. Commented Nov 20, 2013 at 12:49

2 Answers 2

2

Refer this -

For getting Password -

NSString *password = txtPassword.text;

For getting Login Id -

NSString *loginID = txtLoginId.text;

And now,call the above method and pass those variables.

Hope this will help you.Thank you in advance.

Sign up to request clarification or add additional context in comments.

3 Comments

ok, thank You - this should really help me. Another question: how i can define that txtPassword will reffer to my textField value?
Welcome.You can refer me for any query. :)
create the iBOutlet from your storyboard to .h file and give the name as txtPassword, to create IBOutlet simply control-drag from your storyboard viewcontroller to your .h file and give the name
0

simply pass the UITextField.text value to -(id)initWithLogin:(NSString *)_login password:(NSString *)_password method e.g..

suppose you have two textfields one for login and other for password then create the object and pass the values

YourClassName *class = [[YourClassName alloc] initWithLogin:loginTextField.text password:passowrdTextField.text];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.