Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 退出alertview中存在的文本字段的键盘_Iphone_Keyboard_Uitextfield - Fatal编程技术网

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

Iphone 退出alertview中存在的文本字段的键盘,iphone,keyboard,uitextfield,Iphone,Keyboard,Uitextfield,我在alertview上有三个文本字段,我将键盘设置为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; sel

我在alertview上有三个文本字段,我将键盘设置为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方法中添加了ResignFirstResponder方法,请看这里

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

创建
UITextField
的iVar,并在
UITextFieldDelegate
方法
textFieldShouldBeginEditing
中赋值。希望它能起作用

如下图所示:

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


当你按下警报视图上的OK按钮时,键盘会自动关闭。我已经测试过了,所以请从上述方法中删除辞职FirstResponder,并尝试一下上面的方法。我应该添加什么,请在我的项目中详细说明辞职键bord两次,但第三次没有回复,为什么,这是警报视图的问题还是在.h文件中使用三个文本字段为UITextField创建实例变量的问题,例如:UITextField*activeField;将此方法赋值给textField应该像activeField=textField一样开始编辑;试一下。。。
- (void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    [self.view endEditing: YES];
}