gpt4 book ai didi

ios - 如何使用后台点击隐藏数字键盘?

转载 作者:可可西里 更新时间:2023-11-01 06:23:45 25 4
gpt4 key购买 nike

我使用 this book 研究 iOS SDK在第 4 章中,当它告诉您如何使用背景点击隐藏数字键盘时,我遇到了问题。我照作者说的做,但什么也没发生。我该怎么做? 书的作者说了什么:

1)在ViewController.h中新建方法backgroundTap

- (IBAction)touchBackground:(id)sender;

2)在ViewController.m中添加方法

-(void)touchBackground:(id)sender{
[nameField resignFirstResponder];
[numberField resignFirstResponder];}

3) 将 Interface Builder 中的 View 对象的类标识(正如我在 Xcode 4 中对其 Control 的理解)从 UIView 更改为 UIControl

4)将事件列表中的 TouchDown 方法与 File's Owner 连接起来,并检查方法 backgroundTap。

这是我的代码示例

附言我很抱歉我的英语不好,我把书中的所有信息都翻译成了英语,因为我有俄语翻译。

最佳答案

我想你可以通过实现这样的方法来简化这个过程:

- (IBAction)backgroundTouched:(id)sender {
[self.view endEditing:YES];
}

在界面生成器中制作背景 View UIControl 而不是 UIView 并将 touches up 事件挂接到此方法。

看看这个small example project .我在 secondViewController 中正是这样做的,触摸背景会关闭键盘。您还可以在 secondViewController.xib

中看到我如何将背景更改为 UIControl

关于ios - 如何使用后台点击隐藏数字键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8626225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com