views:

467

answers:

1

I want to disable input pad on iphone when pressing 'done'. Any ideas about how to detect button press event?

+3  A: 

Programatic Method

To register button press events you can either do the programmatic approach:

[button addTarget:self action:@selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside]

Where buttonPressed: is a method in the class "self":

-(void)buttonPressed:(id)sender;

You can specify a pointer to any object instead of "self" of course, as long as the object has a buttonPressed: method.

Interface Builder

You can also use Interface Builder. Create a method that you want to execute:

-(IBAction)buttonPressed:(id)sender;

Then right click on the button in interface builder. You should see a list of actions. On the "touch up" action click on the circle button, and drag a connector to the object representing the class where you put the buttonPressed: method.

Disabling Input Pad

I'm not sure what you mean by this. Are you talking about dismissing a keyboard input? If so, you have to call the "resignFirstResponder:" method. Say, for example, the keyboard pops up because you are editing a text field. To dismiss the keyboard call the following method on the text field:

[textField resignFirstResponder];
DasBoot
The 'Done' button on keyboard input is invisible in interface builder. Can I add an action to the button to dismiss the keyboard?
iPhoney
There is an option (you can find it in IB) that makes the done button invisible until you enter text. You can disable this.
DasBoot
For your question about how to dismiss the keyboard. You can implement the UITextFieldDelegate protocol in your class. That delegate has methods that get called when the keyboard's done button is pressed.
DasBoot
Once you detect that the done button is pressed then you can dismiss the keyboard by using the resignFirstResponder: as mentioned in the answer.
DasBoot