How to add textField in UIAlertController?

前端 未结 3 1956
梦谈多话
梦谈多话 2020-12-04 18:59

I want to realize a function about changing password. It requires users to input their previous password in an alert dialog.

I want to click the button \"Confirm the

3条回答
  •  粉色の甜心
    2020-12-04 19:45

    You can add multiple textfields to alert controller and access them with the alert controller's textFields property

    If the new password is an empty string, present the alert again. Or another way would be to disable the "Confirm" button, enabling it only when text field has text.

    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"confirm the modification" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        UITextField *password = alertController.textFields.firstObject;
        if (![password.text isEqualToString:@""]) {
    
            //change password
    
        }
        else{
            [self presentViewController:alertController animated:YES completion:nil];
        }
    }];
    

提交回复
热议问题