gpt4 book ai didi

ios - 具有多个文本输入的 UIAlertView?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:26:22 24 4
gpt4 key购买 nike

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Add new work order (TEST)" message:@"Please fill out all fields" delegate:self cancelButtonTitle:@"Add" otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *alertTextFieldName = [alert textFieldAtIndex:0];
alertTextFieldName.placeholder = @"Work order name";
alertTextFieldName.keyboardType = UIKeyboardTypeDefault;
UITextField *alertTextFieldProjectNo = [alert textFieldAtIndex:1];
alertTextFieldProjectNo.placeholder = @"ProjectNo";
alertTextFieldProjectNo.keyboardType = UIKeyboardTypeDefault;
UITextField *alertTextFieldSubName = [alert textFieldAtIndex:2];
alertTextFieldSubName.placeholder = @"Sub account name";
alertTextFieldSubName.keyboardType = UIKeyboardTypeDefault;
[alert show];

我正在尝试这样做,但出现错误:NSRangeException',原因:'*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

难道我不能向 aletView 添加多个文本字段吗? -textFieldAtIndex: 让我知道这是可能的。我错了吗?

最佳答案

将此代码用于在 UIAlertView 中添加多个文本字段

UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 100)];

UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(10,0,252,25)];
textField1.borderStyle = UITextBorderStyleRoundedRect;
textField1.placeholder = @"Username";
textField1.keyboardAppearance = UIKeyboardAppearanceAlert;
textField1.delegate = self;
[v addSubview:textField1];

UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(10,30,252,25)];
textField2.placeholder = @"Password";
textField2.borderStyle = UITextBorderStyleRoundedRect;
textField2.keyboardAppearance = UIKeyboardAppearanceAlert;
textField2.delegate = self;
[v addSubview:textField2];


UITextField *textField3 = [[UITextField alloc] initWithFrame:CGRectMake(10,60,252,25)];
textField3.placeholder = @"Address";
textField3.borderStyle = UITextBorderStyleRoundedRect;
textField3.keyboardAppearance = UIKeyboardAppearanceAlert;
textField3.delegate = self;
[v addSubview:textField3];


UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"TEST" message:@"" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
[av setValue:v forKey:@"accessoryView"];
[av show];

希望这段代码对你有用。

关于ios - 具有多个文本输入的 UIAlertView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29316791/

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