1

i need to add button done on keypad.

Apple does n't provide such felicity but some of application i found that done ,next,previous buttons.

like this.

how can i add these and how can i give click event to them.

can any one please help me.

Mahesh Babu
  • 3,395
  • 9
  • 48
  • 97

1 Answers1

2

1.Define the done button (= return key):

textField.returnKeyType = UIReturnKeyDone;

2.Add the action-listener:

[textField addTarget:self action:@selector(textFieldDoneEditing:) forControlEvents:UIControlEventEditingDidEndOnExit];

3.Define the action-event:

- (IBAction)textFieldDoneEditing:(id)sender {
    [sender resignFirstResponder];
}

Have fun!

EDIT:

Here you can find detailed instructions how to add a Toolbar with Next & Previous above UITextField Keyboard: http://www.randomsequence.com/articles/adding-a-toolbar-with-next-previous-above-uitextfield-keyboard-iphone/

EDIT2:

Now, I have a really great example for you: "This view extends UITextView adding on top of the keyboard associated with this UITextView a toolbar with a « Done » Button"

I check the code and it is a lot of easier than the first example:

http://blog.demay-fr.net/2009/07/cocoa-how-to-add-a-toolbar-with-button-on-top-of-a-uitextview-in-order-to-add-a-dismiss-button/

EDIT3:

Hmmm, no, I doesn't test to code. But I will test it now!

1.Problem: the right initialization. If I add the UITextView in IB, initWithCoder gets called:

- (id)init {

    NSLog(@"init");

    if (self = [super init]) {
        //register a specific method on keyboard appearence
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)decoder {

    NSLog(@"initWithCoder");

    if (self = [super initWithCoder:decoder]) {
        //register a specific method on keyboard appearence
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame {

    NSLog(@"initWithFrame");

    if (self = [super initWithFrame:frame]) {
        //register a specific method on keyboard appearence
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    }
    return self;
} 

2.Problem: There's no view with the the Prefix "UIKeyboard":

for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {
    NSLog(@"keyboardWindow = %@", keyboardWindow);
    for (UIView *keyboard in [keyboardWindow subviews]) {
        NSLog(@"keyboard = %@", keyboard);

            if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) {
                // THERE'S NO VIEW 'UIKeyboard'!!!
            }

    }
}

The code doesn't work, I'm sorry... I don't know why there's no view "UIKeyboard"... Maybe the first example will help you at this point and you can build your own solution.

Manni
  • 11,108
  • 15
  • 49
  • 67
  • Thank u Manni,But i need only done button,when i click it,i need to hide keyboard.I am getting confusion with this Tutorial.If u have any sample please post it – Mahesh Babu Feb 03 '11 at 10:57
  • I found a second example with a Done-Button on top of the keyboard. I hope that helps you :-) (look EDIT2) – Manni Feb 03 '11 at 11:56
  • I tried this(EDIT2),but does n't work,I did n't get any tool bar on the key board.Did u test this. – Mahesh Babu Feb 04 '11 at 04:37
  • ya, Thank u for u r helping Manni,I use first link,That resolve my problem – Mahesh Babu Feb 04 '11 at 07:40