添加“完成”和“新线” iPhone 应用程序键盘上的按钮

发布于 2024-10-15 22:07:18 字数 257 浏览 3 评论 0原文

我创建了一个基于窗口的应用程序,其中使用 UITabbarController 作为 RootViewController。 在其中一个选项卡中,我提供了 UITextFieldUITextView。 我想在键盘本身上提供两个按钮:

  • 完成 - 这将隐藏键盘。
  • 输入 - 换行。

如果有人知道如何做,请发布您的答案。

I have created a window based application with a UITabbarController as the RootViewController.
In one of the tabs, i have provided UITextField and UITextView.
I want to provide two buttons on the keyboard itself:

  • Done - which will hide the keyboard.
  • Enter - for new line.

Please post your answer if anybody has some idea how to do it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不打扰别人 2024-10-22 22:07:18

对于 UITextField,您可以通过设置以下内容将返回键更改为完成键:

targetTextField.returnKeyType = UIReturnKeyDone;

但是,如果不向键盘自定义添加视图,您将无法同时拥有 Enter 和 Done 键。

另外,要控制键盘的完成行为,您必须实现 UITextFieldDelegate 方法:

targetTextField.delegate = self;
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
     return YES;  //dismisses the keyboard
}

我知道您可以为 UITextView 设置 returnKeyType 但我不确定您是否可以操纵返回键行为。

For the UITextField you can change the return key to a done key by setting the following:

targetTextField.returnKeyType = UIReturnKeyDone;

However, you won't be able to have a Enter and Done key at the same time without custom addition of views to the keyboard.

Also, to control the done behavior of the keyboard you have to implement a UITextFieldDelegate method:

targetTextField.delegate = self;
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
     return YES;  //dismisses the keyboard
}

I know you can set the returnKeyType for a UITextView but I'm not sure if you can manipulate the return key behavior.

久夏青 2024-10-22 22:07:18

您在此处有有关如何将子视图添加到 iPhone 键盘的教程:

http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/7350-adding-subviews-cusstimize-keyboard.html

希望这有帮助,
文森特

You have a tutorial on how add subviews to the iPhone keyboard here :

http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/7350-adding-subviews-custimize-keyboard.html

Hope this helps,
Vincent

允世 2024-10-22 22:07:18

由于某种原因返回 YES;本身不起作用。这对我有用:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {

    if (textField.returnKeyType == UIReturnKeyNext) {
        NSInteger nextTag = textField.tag + 1;
        // Try to find next responder
        UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
        if (nextResponder) {
            // Found next responder, so set it.
            [nextResponder becomeFirstResponder];
        }
    }

    if (textField.returnKeyType == UIReturnKeyDone) {
        [textField resignFirstResponder];
    }
    return YES;  //dismisses the keyboard
}

For some reason return YES; didn't work on its own. that worked for me :

- (BOOL)textFieldShouldReturn:(UITextField *)textField {

    if (textField.returnKeyType == UIReturnKeyNext) {
        NSInteger nextTag = textField.tag + 1;
        // Try to find next responder
        UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
        if (nextResponder) {
            // Found next responder, so set it.
            [nextResponder becomeFirstResponder];
        }
    }

    if (textField.returnKeyType == UIReturnKeyDone) {
        [textField resignFirstResponder];
    }
    return YES;  //dismisses the keyboard
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文