gpt4 book ai didi

ios - 如何在 iOS 的 UIAlertView 中添加 3 个 UITextField?

转载 作者:行者123 更新时间:2023-11-28 18:55:08 25 4
gpt4 key购买 nike

我想在 UIAlertView 中添加 3 个 TextField,例如 oldpassword、Newpassword、confirmpassword 这样的。这是我试过的代码

-(IBAction)changePswd:(id)sender
{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Change Password" message:@"Enter Your New Password" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"submit", nil];
[alertView setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
[[alertView textFieldAtIndex:0]setSecureTextEntry:YES];
[alertView textFieldAtIndex:0].keyboardType = UIKeyboardTypeDefault;
[alertView textFieldAtIndex:0].returnKeyType = UIReturnKeyDone;
[[alertView textFieldAtIndex:0]setPlaceholder:@"Enter Your Old Password"];
[[alertView textFieldAtIndex:1]setPlaceholder:@"Enter password"];
[[alertView textFieldAtIndex:2]setPlaceholder:@"Re-Enter Password"];
[alertView show];
}

它只显示两个文本框。

最佳答案

为此使用 UIAlertController。

UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];

__block typeof(self) weakSelf = self;

//old password textfield
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.tag = 1001;
textField.delegate = weakSelf;
textField.placeholder = @"Old Password";
textField.secureTextEntry = YES;
[textField addTarget:weakSelf action:@selector(alertTextFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
}];

//new password textfield
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.tag = 1002;
textField.delegate = weakSelf;
textField.placeholder = @"New Password";
textField.secureTextEntry = YES;

}];

//confirm password textfield
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.tag = 1003;
textField.delegate = weakSelf;
textField.placeholder = @"Confirm Password";
textField.secureTextEntry = YES;
[textField addTarget:weakSelf action:@selector(alertTextFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
}];

[self presentViewController:alertController animated:YES completion:nil];

#pragma mark - UITextField Delegate Methods
- (void)alertTextFieldDidChange:(UITextField *)sender
{
alertController = (UIAlertController *)self.presentedViewController;
UITextField *firstTextField = alertController.textFields[0];
}

关于ios - 如何在 iOS 的 UIAlertView 中添加 3 个 UITextField?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34769107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com