Как добавить текстовое поле для просмотра предупреждений? Xcode 4.5 iOS6

Как добавить текстовое поле в представление оповещений? Я пытаюсь создать приложение, в котором перед тем, как приложение завершит редактирование, пользователь должен сначала выполнить аутентификацию, введя свой пароль в указанном предупреждении, но как я могу это сделать? Кажется, что код, который я искал, больше не работает. Вот:

  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Log In" message:@"Please enter your Password" delegate:self cancelButtonTitle:@"Log In" otherButtonTitles:@"Cancel", nil];
    [alert addTextFieldWithValue:@"" label:@"Password"];
    UITextField *tf = [alert textFieldAtIndex:0];
    tf.clearButtonMode = UITextFieldViewModeWhileEditing;
    tf.keyboardType = UIKeyboardTypeAlphabet;
    tf.keyboardAppearance = UIKeyboardAppearanceAlert;
    tf.autocapitalizationType = UITextAutocapitalizationTypeWords;
    tf.autocapitalizationType = UITextAutocorrectionTypeNo;

ошибка сказала

 "No visible @interface for 'UIAlertView' 
 declares the selector 'addTextFieldWithValue:label:'" 
 on the [alert addTextFieldWithValue:@"" label:@"Password"];

Я также хотел бы спросить, как я могу поставить коды на кнопку "Подтвердить" в окне просмотра предупреждений.

2 ответа

Решение
alert.alertViewStyle = UIAlertViewStylePlainTextInput;

или если вам нужно, чтобы это было безопасно (для паролей)

alert.alertViewStyle = UIAlertViewStyleSecureTextInput;

Редактировать:

Я не уверен на 100%, что вы подразумеваете под "поставить коды на кнопку подтверждения", но если вы хотите знать, нажали ли они подтверждение или отмену, вам нужно только реализовать

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    //check the button index and do something if it's the right one.
}

Добавление textField в представление предупреждений (Swift):

    let pincodeAlert:UIAlertController = UIAlertController(title: "Hello", message: "Enter a new passcode", preferredStyle: UIAlertControllerStyle.Alert)
           pincodeAlert.addTextFieldWithConfigurationHandler({ (pinCodeTextField:UITextField!) -> Void in
            pinCodeTextField.placeholder = "password"
            pinCodeTextField.secureTextEntry = true
           })
    //Add the textField       
    pincodeAlert.addTextFieldWithConfigurationHandler({ (pinCodeTextField2:UITextField!) -> Void in
            pinCodeTextField2.placeholder = "Confirm password"
            pinCodeTextField2.secureTextEntry = true
           })

    pincodeAlert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (action) -> Void in
                //check entered passcodes
                }))
                pincodeAlert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
                presentViewController(pincodeAlert, animated: true, completion: nil)

Чтобы проверить данные в checkBoxes, просто добавьте это в свой обработчик действия "OK":

let passcodeEntered:String = (pincodeAlert.textFields?.first as UITextField).text
Другие вопросы по тегам