Как создать uitextfield динамически с помощью цикла for - PullRequest
0 голосов
/ 29 ноября 2010

Я пытаюсь создать поле uitext динамически, но не могу создать имя текстового поля. Кто-нибудь знает, пожалуйста, помогите мне.

Ответы [ 3 ]

2 голосов
/ 29 ноября 2010

из Как создать текстовое поле?

Чтобы создать текстовое поле, используйте класс 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;
1 голос
/ 29 ноября 2010

Назначьте тег для каждого UITextField ..

, затем получите доступ к textField, используя

UITextField *tf=(UITextField *)[yourView viewWithTag:tag];
0 голосов
/ 11 октября 2013
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];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...