iphone - 添加和删​​除键盘

标签 iphone objective-c cocoa-touch iphone-softkeyboard

我有一个文本字段,当用户单击它时,他们将看到键盘。键盘上有一个 GO 按钮,我想向其写入一个 action 事件。

1.) 当用户单击此按钮时,如何编写操作

2.)当键盘打开时,当用户单击背景时,我需要键盘消失,我如何以编程方式执行此操作?

我没有代码可以演示,我只添加了一个文本字段,因此单击后默认会出现键盘

最佳答案

要在返回文本字段/“转到”按钮时执行某些操作,请使用以下代码

-(BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    [theTextField resignFirstResponder];

    //call Method when the GO button is pressed   

    return YES;
}

当用户触摸背景时键盘应该返回 - 为此,编写下面的代码

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

[textFiedl resignFirstResponder];

}

希望您的问题能够得到解决。

关于iphone - 添加和删​​除键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8707112/

相关文章:

ios - 使用 glob 获取目录中的文件列表

iphone - 隐藏和显示间歇性 uilabel 和 uinavigation 标题?

iphone - 重新加载/刷新按钮刷新 UIView 中的对象/数据

iphone - 在 uitableviewcontroller 顶部添加新对象

ios - 访问 NSOperation 上的属性

iphone - 这意味着什么? "mi_cmd_stack_list_frames: Not enough frames in stack."

iphone - 在 -loadView 中正确调整 View 大小

iphone - UIButton 状态

ios - 访问文件属性与访问 sqlite 记录

ios - UICollectionView 使用不同高度的单元格