Нет клавиатуры с UIAlertViewStylePlainTextInput? - PullRequest
3 голосов
/ 13 января 2012

У меня проблема с 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;

, но клавиатура не появляется.

(я тестировал его на своем устройстве и на симуляторе)

У вас есть какие-либо идеи по этому поводу?

Заранее спасибо.

Ответы [ 3 ]

4 голосов
/ 19 сентября 2012

У меня была проблема, потому что я запускал оповещение, когда в моем представлении вызывался метод делегата UITextField textFieldDidBeginEditing, а затем я заполнял его содержимым текстового поля представления оповещения. Это означало, что UITextField, на мой взгляд, стал первым респондентом, и я не мог найти способ уйти в отставку. Так что, если у вас есть проблема, это потому, что что-то еще становится первым респондентом, прежде чем отображается UIAlert. Подумайте, как вы вызываете предупреждение.

Я смирился с использованием жеста касания на моем UITextField, который затем вызывает UIAlertView с UIAlertViewStylePlainTextInput, и он отлично работает.

Некоторый код ниже:

-(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]; 
}
1 голос
/ 02 марта 2012

Попробуйте код ниже:

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

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

Работает на iOS5

0 голосов
/ 20 сентября 2012

Может исправить вашу проблему, так как она решила мою:

[enter resignFirstResponder];
...