在运行时编辑多个动态生成的UITextField

时间:2011-07-15 10:06:01

标签: ios dynamic uitextfield touch

我已经创建了一个应用程序,用户可以根据需要生成任意数量的UITextField,这些应用程序将自动放在UIView上。功能是用户可以在屏幕的任何位置拖动任何UITextField。直到这一部分,每件事都很有效。现在,如果他想编辑UITextField,他会在UITextField和edits上点击(2次)。我的这部分只适用于最近生成的UITextField。我怎样才能做到这一点?我想知道我之前可以发布的代码。请回应它。提前致谢。

1 个答案:

答案 0 :(得分:0)

        add textFieldArray to .h file then specify <UITextFieldDelegate> and

        sythesize that array.


        while creating the each textfield

        specify delegate like this

        mytextF1.delegate=self;

        mytextF2.delegate=self;

        .....


        after that add all text field object to an textFieldArray which should be declared .h file and synthesize them .(dont forget to alloc and init this array in ur viewdidload).


        self.textFieldArray=[[NSMutableArray alloc]init];


        then add each text field to this array

        [self.textFieldArray addObject:mytextF1];

        [self.textFieldArray addObject:mytextF2];

        .......

        then use this delegate methode to update

        - (void)textFieldDidBeginEditing:(UITextField *)textField{



            for (UITextField *textF in self.textFieldArray) {

                [textF setText:[textField text]];

            }



        }