退出AlertView中存在的文本字段的键盘

退出AlertView中存在的文本字段的键盘

本文介绍了退出AlertView中存在的文本字段的键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在alertview上有三个文本字段,我将键盘设置为decimalType,

I have three text fields on an alertview, I set keyboard as decimalType ,

- (IBAction)heightMethod:(id)sender

{

 self.utextfield = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)]; utextfield.placeholder = @"  Centimeters";

self.utextfield.delegate=self;

self.utextfield.tag=3;
[ self.utextfield setBackgroundColor:[UIColor whiteColor]];
[self.alertHeight addSubview: self.utextfield];
// Adds a password Field
self.ptextfield = [[UITextField alloc] initWithFrame:CGRectMake(40, 80.0, 80, 25.0)]; ptextfield.placeholder = @"   Feet";
self.ptextfield.delegate=self;
self.ptextfield.tag=4;

[self.ptextfield setBackgroundColor:[UIColor whiteColor]];
[self.alertHeight addSubview:self.ptextfield];

self.ptextfieldInches = [[UITextField alloc] initWithFrame:CGRectMake(140, 80.0, 80, 25.0)]; ptextfieldInches.placeholder = @"   Inches";
self.ptextfieldInches.delegate=self;
self.ptextfieldInches.tag=5;


[ptextfieldInches setBackgroundColor:[UIColor whiteColor]];
[self.alertHeight addSubview:ptextfieldInches];

 [self.utextfield setKeyboardType:UIKeyboardTypeDecimalPad];
 [self.ptextfieldInches setKeyboardType:UIKeyboardTypeDecimalPad];
 [self.ptextfield setKeyboardType:UIKeyboardTypeDecimalPad];

[self.alertHeight show];

}

当我点击任何文本字段时,键盘只会退出两次,但是第三次​​它不会退出.我在alertview的delgate方法中添加了resignfirst响应器方法,请看这里

As I tap any textfield, keyboard resign only two times, but on third time its not resigning . I added resignfirst responder method inside the delgate method of alertview , look here

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

推荐答案

创建 UITextField 的iVar,并在侧面的 UITextFieldDelegate 方法 textFieldShouldBeginEditing 中进行分配.希望它能工作.

Create iVar of UITextField and assign in side UITextFieldDelegate method textFieldShouldBeginEditing. Hopefully it should work.

像下面这样:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
   textField = iVar;
}

这篇关于退出AlertView中存在的文本字段的键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 22:18