0

我在警报视图上有三个文本字段,我将键盘设置为 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 responder 方法,看这里

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

3 回答 3

1

创建 iVarUITextField并在 sideUITextFieldDelegate方法中分配textFieldShouldBeginEditing。希望它应该工作。

如下:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
   textField = iVar;
}
于 2013-03-27T05:39:35.823 回答
0

尝试

- (void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    [self.view endEditing: YES];
}
于 2013-03-27T11:52:32.873 回答
0

当您在警报视图上按 OK 按钮时,键盘会自动关闭。我已经对其进行了测试,因此请从上述方法中删除resignfirstresponder并尝试

于 2013-03-27T12:50:28.160 回答