如何在键盘中添加完成按钮 [英] how to add done button in keypad

查看:114
本文介绍了如何在键盘中添加完成按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在键盘上添加按钮。

i need to add button done on keypad.

Apple没有提供这样的幸福感,但是我发现有些应用程序已完成,下一步,上一个按钮。

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

喜欢这样

我如何添加这些以及如何向他们提供点击事件。

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

任何人都可以帮助我。

can any one please help me.

推荐答案

1.定义完成按钮(=返回键):

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

textField.returnKeyType = UIReturnKeyDone;

2.添加动作监听器:

2.Add the action-listener:

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

3.定义动作事件:

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

玩得开心!

编辑:

您可以在此处找到有关如何添加工具栏的详细说明与Next&上面的UITextField键盘:
http://www.randomsequence.com/articles/adding-a-toolbar-with-next-previous-above-uitextfield-keyboard-iphone/

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:

现在,我有一个很好的例子:这个视图扩展了UITextView在键盘上的添加与此UITextView关联的工具栏带有完成»按钮

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-a-uxtxt-on-order-to-add-a-dismiss-button /

EDIT3:

嗯,不,我不测试代码。但我现在要测试它!

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

1.问题:正确的初始化。如果我在IB中添加UITextView,则会调用initWithCoder:

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.问题:前缀UIKeyboard没有视图:

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'!!!
            }

    }
}

代码不起作用,对不起......我不知道为什么没有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.

这篇关于如何在键盘中添加完成按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆