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

Ios 在运行时编辑多个动态生成的UITextFields,ios,dynamic,uitextfield,touch,Ios,Dynamic,Uitextfield,Touch,我制作了一个应用程序,用户可以根据自己的需要生成尽可能多的UIExtField,这些UIExtField将自动放置在UIView上。功能是用户可以在屏幕的任何位置拖动UITextField中的任何一个。在这部分之前,一切都很正常。现在,如果他想编辑UITextField,他在UITextField上点击(2次)并进行编辑。我的这部分内容仅适用于最近生成的UITextField,而不是所有的UITextField。我该怎么做?我想没有人想要我以前的代码,我可以发布。请你马上回答。提前谢谢 将tex

我制作了一个应用程序,用户可以根据自己的需要生成尽可能多的UIExtField,这些UIExtField将自动放置在UIView上。功能是用户可以在屏幕的任何位置拖动UITextField中的任何一个。在这部分之前,一切都很正常。现在,如果他想编辑UITextField,他在UITextField上点击(2次)并进行编辑。我的这部分内容仅适用于最近生成的UITextField,而不是所有的UITextField。我该怎么做?我想没有人想要我以前的代码,我可以发布。请你马上回答。提前谢谢

将textFieldArray添加到.h文件,然后指定
        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]];

            }



        }
合成该数组。 在创建每个文本字段时 像这样指定委托 mytextF1.delegate=self; mytextF2.delegate=self; ..... 之后,将所有文本字段对象添加到一个textFieldArray中,该数组应声明为.h文件并合成它们(不要忘记在您的viewdidload中分配并初始化该数组)。 self.textFieldArray=[[NSMutableArray alloc]init]; 然后将每个文本字段添加到此数组中 [self.textFieldArray addObject:mytextF1]; [self.textFieldArray addObject:mytextF2]; ....... 然后使用此委托方法进行更新 -(无效)textFieldDidBeginEditing:(UITextField*)textField{ for(self.textFieldArray中的UITextField*textF){ [textF setText:[textField text]]; } }
Hey@Madhu感谢您的回复,但问题是我无法定义任何数组,因为数组的大小无法固定,因为文本字段是由用户在运行时生成的,我们没有任何固定大小。我刚刚实现了要编辑的委托函数,但这仅适用于最近生成的UITextField,即使我的触摸屏识别出以前的UITextFields。每当用户创建textfield时,只需将[self.textFieldArray addObject:mytextF1]。它将添加和增加尽可能多的文本字段。因此,不必担心创建了多少textfield。给我更多关于动态创建textfield函数的代码,我将解析u//此代码用于动态生成UItextFields!!如果(textGenerated){textOnView=[[UITextField alloc]initWithFrame:CGRectMake(0,0,长度*(sizeText),sizeText+10)];textOnView.text=text;textOnView.font=[UIFont-fontWithName:font-size:sizeText];textOnView.center=BackGround.center;[textOnView-setTextAlignment:UITextAlignmentCenter];textOnView.delegate=self;[self.view addSubview:textOnView];}