gpt4 book ai didi

iphone - 将 3 个 UItextfield 中的数据分配到 3 个不同的字符串中

转载 作者:行者123 更新时间:2023-11-29 04:12:35 24 4
gpt4 key购买 nike

我试图从 3 个不同的 Uitextfields 获取 3 个不同的值,然后将它们保存到 1 个字符串中,以通过按钮操作将其发送到 REST API 服务器。我不知道如何从 3 个 UItextfields 获取所有 3 个文本输入。有什么想法吗?我的文本字段是帐户、用户名、密码。

UITextField *account = [[UITextField alloc] initWithFrame:CGRectMake(90, 50, 140, 30)];
account.borderStyle = UITextBorderStyleRoundedRect;
account.font = [UIFont systemFontOfSize:14];
account.placeholder = @"Account";
account.autocorrectionType = UITextAutocorrectionTypeNo;
account.keyboardType = UIKeyboardTypeDefault;
account.returnKeyType = UIReturnKeyDone;
account.clearButtonMode = UITextFieldViewModeWhileEditing;
account.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
account.delegate = self;
[self.view addSubview:account];
[account release];


UITextField *username = [[UITextField alloc] initWithFrame:CGRectMake(90, 80, 140, 30)];
username.borderStyle = UITextBorderStyleRoundedRect;
username.font = [UIFont systemFontOfSize:14];
username.placeholder = @"User ID";
username.autocorrectionType = UITextAutocorrectionTypeNo;
username.keyboardType = UIKeyboardTypeDefault;
username.returnKeyType = UIReturnKeyDone;
username.clearButtonMode = UITextFieldViewModeWhileEditing;
username.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
username.delegate = self;
[self.view addSubview:username];
[username release];

UITextField *password = [[UITextField alloc] initWithFrame:CGRectMake(90, 110, 140, 30)];
password.borderStyle = UITextBorderStyleRoundedRect;
password.font = [UIFont systemFontOfSize:14];
password.placeholder = @"Password";
password.autocorrectionType = UITextAutocorrectionTypeNo;
password.keyboardType = UIKeyboardTypeDefault;
password.secureTextEntry = YES;
password.returnKeyType = UIReturnKeyDone;
password.clearButtonMode = UITextFieldViewModeWhileEditing;
password.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
password.delegate = self;
[self.view addSubview:password];
[password release];

使用时找不到获取所有 3 个数据的方法:

 -(void) textFieldDidEndEditing:(UITextField *)textField

函数。

提前致谢!

最佳答案

设置文本字段标签

    userNameTextField.tag = 1
accountTextField.tag = 2
passwordTextField.tag = 3

将值保存在shouldChangeCharactersInRange

   - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

switch (textField.tag) {
case 1:
//userNameTextField
NSString *userNameTextField = [NSString stringWithFormat:@"%@%@",textField.text,string];
//save
break;
case 2:
//accountTextField
NSString *accountTextField = [NSString stringWithFormat:@"%@%@",textField.text,string];
//save
break;
case 3:
//passwordTextField
NSString *passwordTextField = [NSString stringWithFormat:@"%@%@",textField.text,string];
//save
break;
default:
break;
}

}

关于iphone - 将 3 个 UItextfield 中的数据分配到 3 个不同的字符串中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14198349/

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