【发布时间】:2011-12-17 10:19:39
【问题描述】:
我创建了带有警报视图的 UITextField。在 UITextField 上键入后,我想在用户单击“完成”按钮时隐藏键盘。
这是我的代码。当我运行它时,它正在使用 hideKeyBoard 方法(我发现使用 NSLog 和调试)。但是这段代码没有隐藏键盘。请帮我。
- (IBAction)doAlertInput:(id)sender
{
UIAlertView *alertDialog;
alertDialog = [[UIAlertView alloc]
initWithTitle: @"Please Enter Your Email Address!" message:@"You won’t see me"
delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
userInput=[[UITextField alloc] initWithFrame: CGRectMake(12.0, 70.0, 260.0, 25.0)];
userInput.returnKeyType = UIReturnKeyDone;
[userInput addTarget:self action:@selector(hideKeyBoard) forControlEvents:UIControlEventEditingDidEndOnExit];
[userInput setBackgroundColor:[UIColor whiteColor]];
[alertDialog addSubview:userInput];
[alertDialog show];
[alertDialog release];
}
-(void)hideKeyBoard
{
[userInput resignFirstResponder];
NSLog(@"Key Board Hid");
}
【问题讨论】:
标签: iphone keyboard uitextfield hide uialertview