iPhone应用程序xcode,试图通过点击背景来隐藏文本输入?
我按照 Beginning Iphone Development 4 中的示例进行基本的用户交互。
我正在使用 xcode 4.02 和 sdk 4.3
我有一个基本的 viewcontroller.xib ,其中有两个文本框,一个用于数值,另一个用于文本。完成编辑任一文本字段后,我希望点击背景并使键盘消失。
书中说将容器 UIView 对象更改为 UIControl,然后将操作添加到 UIControl 事件 Touch Down 上。然后创建一个方法来放弃每个文本框的第一响应者,并将其链接到触地事件。我已经做到了这一点。这是我的代码,有什么我错过的吗?目前什么也没有发生。
谢谢
@interface ControlFunViewController : UIViewController {
UITextField *nameField;
UITextField *numberField;
}
@property (nonatomic, retain) IBOutlet UITextField *nameField;
@property (nonatomic, retain) IBOutlet UITextField *numberField;
- (IBAction)textFieldDoneEditing:(id)sender;
- (IBAction)backgroundTap:(id)sender;
实施:
#import "ControlFunViewController.h"
@implementation ControlFunViewController
@synthesize nameField;
@synthesize numberField;
- (void)dealloc
{
[nameField release];
[numberField release];
[super dealloc];
}
- (IBAction)textFieldDoneEditing:(id)sender {
[sender resignFirstResponder];
}
- (IBAction)backgroundTap:(id)sender {
[nameField resignFirstResponder];
[numberField resignFirstResponder];
}
I'm following an example in Beginning Iphone Development 4 for basic user interaction.
I'm using xcode 4.02 with sdk 4.3
I have a basic viewcontroller.xib with two textbox's, one for numeric values and another for text. Once I'm finished editing either of the text fields I wish to tap the background and have the keypad disappear.
The books says to change the container UIView object to a UIControl and then add an action onto the UIControl event Touch Down. Then create a method to resign the first responder of each of the textbox's and link this to the touch down event. I've done this. Here is my code, is there anything I've missed? At the moment nothing happens.
Thanks
@interface ControlFunViewController : UIViewController {
UITextField *nameField;
UITextField *numberField;
}
@property (nonatomic, retain) IBOutlet UITextField *nameField;
@property (nonatomic, retain) IBOutlet UITextField *numberField;
- (IBAction)textFieldDoneEditing:(id)sender;
- (IBAction)backgroundTap:(id)sender;
Implementation:
#import "ControlFunViewController.h"
@implementation ControlFunViewController
@synthesize nameField;
@synthesize numberField;
- (void)dealloc
{
[nameField release];
[numberField release];
[super dealloc];
}
- (IBAction)textFieldDoneEditing:(id)sender {
[sender resignFirstResponder];
}
- (IBAction)backgroundTap:(id)sender {
[nameField resignFirstResponder];
[numberField resignFirstResponder];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此链接将为您提供帮助。它以几种不同的方式解决了隐藏键盘的问题。 http://www.mobisoftinfotech.com/blog/ iphone/iphone-uitextfield-tutorial-handling-keyboard-interactions/
实际上,今年早些时候我在同一本书中遇到了同样的问题。我意识到我没有仔细阅读,只错过了一个小说明,所以我仔细地重新阅读了它,它起作用了。
This link will help you. It addresses hiding the keyboard in several different ways. http://www.mobisoftinfotech.com/blog/iphone/iphone-uitextfield-tutorial-handling-keyboard-interactions/
I actually had the same exact problem in the same book earlier this year. I realized that I wasn't reading carefully and missed just one small instruction so I re-read it carefully and it worked.
从检查器 -> 类标识部分的标识选项卡将 UIView 更改为 UIControl。
将其添加
到您的 .h 文件中
将其添加到您的 .m 文件中
将您的 tabBackgroupnd 从检查器、操作接收部分连接到 UIVIEW(现在是 UIControl),然后就可以了。如果您有任何问题请告诉我
Change the UIView to UIControl from the identify tab of inspector ->class identity section.
add this
to your .h file
add this to your .m file
connect your tabBackgroupnd from the inspector, action receive section to the UIVIEW (which is an UIControl now) and your good to go. let me know if you have anyproblem
找到答案,我没有连接文本框的插座,因此控制器不存在它们。学校男孩的错误。
http://www.iphonedevbook.com /forum/chapter-4-more-user-interface-fun/4145-backgroundtap.html
Found the answer, I didn't link up the outlets for the text boxes so the controller didn't no they existed. School boy error.
http://www.iphonedevbook.com/forum/chapter-4-more-user-interface-fun/4145-backgroundtap.html