2013-03-27 68 views
0

我有一個alertview三個文本字段,我將鍵盤作爲decimalType,辭職當前文本框的鍵盤alertview

- (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]; 

} 

當我點擊任意文本框,鍵盤辭職只有兩次,但第三次的不辭職。我加入resignfirst應答方法alertview的delgate方法裏面,看這裏

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

回答

1

創建的UITextField伊娃和側UITextFieldDelegate方法textFieldShouldBeginEditing分配。希望它能工作。

象下面這樣:

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

以上方法我應該添加什麼,請詳細說明 – Youaregreat 2013-03-27 06:01:37

+0

在我的項目中其辭職的關鍵博rd兩次,但在第三次時它沒有響應,爲什麼,這是一些警告視圖或三個文本字段的問題 – Youaregreat 2013-03-27 06:11:41

+0

在.h文件中爲UITextField創建實例變量ex:UITextField * activeField;在這個方法中指定textFieldShouldBeginEditing,如activeField = textField;嘗試一次... – 2013-03-27 07:08:48

0

嘗試

- (void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    [self.view endEditing: YES]; 
} 
0

當按下警報視圖OK按鈕鍵盤駁回automatically.I已經測試出來,所以從上面提到的方法去除resignfirstresponder並嘗試