gpt4 book ai didi

iphone - 从动态生成的文本字段中获取 textfield.text 值

转载 作者:行者123 更新时间:2023-11-29 13:15:51 26 4
gpt4 key购买 nike

我是 Objective C 的新手我正在生成动态 textfields 并尝试在按下按钮时从每个 textfield 获取 .text 值,但我面临的问题只是最后一个 textfield 被抓取例如-如果生成了 3 个动态 textfeilds 并且我分别在 textfeilds 中输入值 1、2、3 我想要所有这些值,但目前我只从最后一个 文本字段

我正在尝试的代码如下//此函数生成动态文本字段

      - (void)dynamicTextboxes {
NSString *string = txt1.text;
int Pointsvalue = [string intValue];
int x;
for (x=0; x < Pointsvalue ; x++)
{
txtFldFrame1 = [[UITextField alloc] initWithFrame:CGRectMake(100,60*x,120,45)];
txtFldFrame1.borderStyle=UITextBorderStyleRoundedRect;
txtFldFrame1.keyboardType=UIKeyboardTypeNumberPad;

[self.view addSubview:txtFldFrame1];
ArrPut=[[NSMutableArray alloc]initWithObjects:txtFldFrame1, nil];
}

}


// function to Acess the values
NSString *string = txt1.text;
int Pointsvalue = [string intValue];
int x;
for (x=0; x < Pointsvalue ; x++)
{
NSString * values=txtFldFrame1.text;
[ArrPut addObject:values];
if(txtFldFrame1.text.length>0)
{

ArrClick=[NSMutableArray array];
[ArrClick addObjectsFromArray:ArrPut];
}
}
NSLog(@"%@",ArrClick);

谁能帮帮我提前致谢

最佳答案

- (void)viewDidLoad
{
[super viewDidLoad];
[self dynamicTextFields];
}
- (void)dynamicTextFields
{
NSString *string = @"3";
int Pointsvalue = [string intValue];
int x;
for (x=1; x < Pointsvalue ; x++)
{
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100,60*x,120,45)];
textField.borderStyle=UITextBorderStyleRoundedRect;
[textField setDelegate:self];
textField.keyboardType=UIKeyboardTypeNumberPad;
textField.tag = x;
[self.view addSubview:textField];
}
}

- (IBAction)btnRetrieveTextFeildValues:(id)sender
{
NSMutableArray *valuesArray = [[NSMutableArray alloc]init];
NSString *string = @"3";
int Pointsvalue = [string intValue];
int x;
for (x=1; x < Pointsvalue ; x++)
{
UITextField *textField = (UITextField *)[self.view viewWithTag:x];
NSLog(@"Text - -%@",textField.text);
if ([textField.text length]!=0)
{
[valuesArray addObject:textField.text];
}
}
NSLog(@"ValuesArray -- %@",valuesArray);
}

关于iphone - 从动态生成的文本字段中获取 textfield.text 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15849351/

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