如何使用for循环动态创建uitextfield

发布于 2024-10-05 04:12:45 字数 50 浏览 1 评论 0原文

我尝试动态创建 uitextfield,但无法创建文本字段名称。任何人都知道请帮助我。

I try to create the uitextfield dynamically, but i can't create the textfield name.Anybody knows please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

与风相奔跑 2024-10-12 04:12:45

来自 如何创建文本字段?

要创建文本字段,请使用 UITextField 类,如清单 11 所示。

清单 11:创建文本字段

CGRect textFieldFrame = CGRectMake(0.0, 0.0, 100.0, 30.0);
UITextField *textField = [[UITextField alloc] initWithFrame:textFieldFrame];
[textField setBorderStyle:UITextFieldBorderStyleBezel];
[textField setTag:1234];
[textField setTextColor:[UIColor blackColor]];
[textField setFont:[UIFont systemFontOfSize:20]];
[textField setDelegate:self];
[textField setPlaceholder:@"<enter text>"];
[textField setBackgroundColor:[UIColor whiteColor]];
textField.keyboardType = UIKeyboardTypeDefault;

from How do I create a text field?

To create a text field, use the UITextField class, as shown in Listing 11.

Listing 11: Creating a text field

CGRect textFieldFrame = CGRectMake(0.0, 0.0, 100.0, 30.0);
UITextField *textField = [[UITextField alloc] initWithFrame:textFieldFrame];
[textField setBorderStyle:UITextFieldBorderStyleBezel];
[textField setTag:1234];
[textField setTextColor:[UIColor blackColor]];
[textField setFont:[UIFont systemFontOfSize:20]];
[textField setDelegate:self];
[textField setPlaceholder:@"<enter text>"];
[textField setBackgroundColor:[UIColor whiteColor]];
textField.keyboardType = UIKeyboardTypeDefault;
转角预定愛 2024-10-12 04:12:45

为每个 UITextField 分配标签..

然后使用访问文本字段

UITextField *tf=(UITextField *)[yourView viewWithTag:tag];

Assign tag for each UITextField..

then access the textField using

UITextField *tf=(UITextField *)[yourView viewWithTag:tag];
§对你不离不弃 2024-10-12 04:12:45
for (int i=0; i<[checklistArray count]; i++) {

[self addUITextFieldMethod:i]

}

-(void) addUITextFieldMethod:(int)y {

   UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(20, 70*y+40, 280, 31)];
    textField.placeholder  = @"Click here to type";
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.font = [UIFont systemFontOfSize:15];
    textField.textAlignment = NSTextAlignmentLeft;
    textField.returnKeyType = UIReturnKeyDefault;
    int DropDownTag = [[NSString stringWithFormat:@"10%d",y]integerValue];
    textField.tag = DropDownTag ;
    textField.delegate = self;
    [textField addTarget:self action:@selector(returnFromKeyboard:) forControlEvents:UIControlEventEditingDidEndOnExit];

    [scrollViewChecklist addSubview:textField];

}
int textFieldTagValue = textField.tag;

/****************方法中的代码******* >*********/

UITextField *myTextField = (UITextField *)[self.view viewWithTag:textFieldTagValue];
        myTextField.text = [arrayTest objectAtIndex:indexPath.row];
for (int i=0; i<[checklistArray count]; i++) {

[self addUITextFieldMethod:i]

}

-(void) addUITextFieldMethod:(int)y {

   UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(20, 70*y+40, 280, 31)];
    textField.placeholder  = @"Click here to type";
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.font = [UIFont systemFontOfSize:15];
    textField.textAlignment = NSTextAlignmentLeft;
    textField.returnKeyType = UIReturnKeyDefault;
    int DropDownTag = [[NSString stringWithFormat:@"10%d",y]integerValue];
    textField.tag = DropDownTag ;
    textField.delegate = self;
    [textField addTarget:self action:@selector(returnFromKeyboard:) forControlEvents:UIControlEventEditingDidEndOnExit];

    [scrollViewChecklist addSubview:textField];

}
int textFieldTagValue = textField.tag;

/****************Code In Your Method****************/

UITextField *myTextField = (UITextField *)[self.view viewWithTag:textFieldTagValue];
        myTextField.text = [arrayTest objectAtIndex:indexPath.row];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文