tags:

views:

311

answers:

3

hi i am new to iphone applixcation development, Please let me know how to pass 2 parameters to login button I want to pass username and password on the button click of login button. i have given in this manner

-(IBAction)Login_Method:(id)sender withpassword:(id)password
{

}
+4  A: 

It is not possible to send 2 parameters in an IBAction method.

What you can do is Create 2 outlets and then connect these to password and username textfields. On Clicking the login button, read the text value from the above 2 outlets.

Your login button action method will be like this

//username and password are UITextfields
-(IBAction)Login_Method:(id)sender
{
  id name=[username text];
  id pass=[password text];
}
Dhanaraj
+1  A: 

As far as I know, IBActions are defined this way:

- (IBAction) actionMethod:(id)sender

Unless your button is subclassed much differently than usual, it is not going to call IBAction with an extra parameter (your withpassword: password).

You will have to use the standard definition above, get the call from the UIButton, and then get the text from your fields and then you can pass that to another method that will do the login with those two fields - unrelated to the UIButton's IBAction.

mahboudz
+1  A: 

Typically, when you link a UIButton to a method in Interface Builder, that method will have no parameters. Technically, it can have zero, one, or two. The first is the sender (the button that was tapped) and the second is the event (the tap).
See the target-action mechanism for controls:

- (void)action
- (void)action:(id)sender
- (void)action:(id)sender forEvent:(UIEvent *)event

Also, you will typically link user inputs (such as UITextField instances) as IBOutlets. Then, you can access the user input through the text property:

// in your interface (header file):
IBOutlet UITextField *userNameTextField;

// in your implementation file:
NSString *userName = userNameTextField.text;

Finally, you should use correct types. Usernames and passwords are probably NSString* (pointers to NSString objects). "id" is the generic type and is not necessary here.

gerry3