2012-01-12 80 views
3

我有一個UIAlertViewStylePlainTextInput的問題。我使用textfield獲得了Alert,但沒有鍵盤出現..?這裏是我的代碼:沒有鍵盤與UIAlertViewStylePlainTextInput?

UIAlertView *enter = [[UIAlertView alloc] initWithTitle:@"Highscores" message:@"Please Enter Your Name" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:@"Abbrechen" nil]; 

enter.alertViewStyle = UIAlertViewStylePlainTextInput; 


UITextField *theTextField = [enter textFieldAtIndex:0]; 
theTextField.placeholder = @"Your Name"; 
theTextField.keyboardAppearance = UIKeyboardAppearanceAlert; 
theTextField.selected = NO; 


[enter show]; 

我已經試過沒有

UITextField *theTextField = [enter textFieldAtIndex:0]; 
theTextField.placeholder = @"Your Name"; 
theTextField.keyboardAppearance = UIKeyboardAppearanceAlert; 
theTextField.selected = NO; 

一部分,但仍然沒有鍵盤上來。

(我測試過它在我的設備上,並在模擬器上)

你有關於任何想法?

預先感謝您。

回答

1

試試下面的代碼:

UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Your name?" 
                message:nil 
               delegate:nil 
             cancelButtonTitle:@"Cancel" 
             otherButtonTitles:@"OK", nil]; 

[message setAlertViewStyle:UIAlertViewStylePlainTextInput]; 
[message show]; 

工程上的iOS5

4

我有問題,因爲我是觸發警報爲UITextField委託方法textFieldDidBeginEditing被稱爲在我看來,然後我會填補這一警報視圖文本字段的內容。這意味着在我看來UITextField成爲第一響應者,我無法找到一個辭職的方式。所以如果你遇到問題,那是因爲在顯示UIAlert之前,其他人正在成爲第一響應者。想想你是如何觸發警報的。

我在我的UITextField上使用輕擊手勢,然後使用UIAlertViewStylePlainTextInput觸發UIAlertView並且工作正常。

一些下面的代碼:

-(void)addTextFieldToView{ 
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 31)]; 
    textField.backgroundColor = [UIColor whiteColor]; 
    textField.borderStyle = UITextBorderStyleRoundedRect; 
    textField.textAlignment = UITextAlignmentCenter; 
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showAlertWithTextField:)]; 
    [textField addGestureRecognizer:tapGestureRecognizer]; 
    [self.view addSubview:textField]; 
} 

-(void)showAlertWithTextField:(UITapGestureRecognizer *)gesture{ 
    UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil]; 
    [dialog setAlertViewStyle:UIAlertViewStylePlainTextInput]; 
    [dialog show]; 
} 
0

可能會解決你的問題,因爲它解決了我的:

[enter resignFirstResponder]; 
+1

你的意思'[進入becomeFirstResponder]'?您當前的代碼隱藏鍵盤 – BBog 2012-09-20 07:15:45