Ios 如何在“添加和删除”按钮上反复添加和删除五个文本字段单击

Ios 如何在“添加和删除”按钮上反复添加和删除五个文本字段单击,ios,objective-c,Ios,Objective C,我想通过从数组中添加按钮单击添加五个文本字段,并通过删除按钮单击删除新添加的文本字段。当我点击添加按钮时,五个文本字段一次又一次地添加,当我点击添加按钮时,它工作正常。但当我点击删除按钮时,只有新增的五个文本字段被删除,而不是一次又一次地点击删除按钮时被删除。 这是我的密码 enter code -(void)CreateTextField//在按钮上创建5个文本字段在单击时反复单击 { NSLog(@“%d”,i) i=i+1; NSArray*阵列; 数组=[[NSArray al

我想通过从数组中添加按钮单击添加五个文本字段,并通过删除按钮单击删除新添加的文本字段。当我点击添加按钮时,五个文本字段一次又一次地添加,当我点击添加按钮时,它工作正常。但当我点击删除按钮时,只有新增的五个文本字段被删除,而不是一次又一次地点击删除按钮时被删除。 这是我的密码

enter code    
-(void)CreateTextField//在按钮上创建5个文本字段在单击时反复单击 { NSLog(@“%d”,i)

i=i+1;
NSArray*阵列;
数组=[[NSArray alloc]initWithObjects:@“学位”@“分支机构”@“通过年份”@“成绩/%”,@“学院”,无];/*这是五个文本字段名
textFieldArray=[[NSMutableArray alloc]init];
对于(int k=0;k<[数组计数];k++)
{
}
-(void)DeleteTextField//通过单击delete按钮删除上一个新添加的文本字段,但仅删除一次,而不是一次又一次地通过单击删除
{
NSLog(@“%lu”,(无符号长)[textFieldArray count]);
int var=[textFieldArray count]-5;
int test=[textFieldArray count];
对于(int p=test;p>var;p--)
{
NSLog(@“%d”,i);
[[textFieldArray objectAtIndex:p-1]removeFromSuperview];/*通过单击删除按钮删除新添加的文本字段的代码
[textFieldArray removeObjectAtIndex:p-1];
}这里

看到您只发布了代码,没有任何描述,我只能假设您需要
CreateTextFields
中的空for循环的代码

试试这个:

float textFieldHeight = 42;
float spacing = 8;
float width = 300;

for(int k = 0; k < [array count]; k++)
{
     UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(x, i*(textFieldHeight + spacing), width, textFieldHeight)];
     // ... other things you'd like to do with the textField
     [textFieldArray addObject:textField];
}
float textFieldHeight=42;
浮动间距=8;
浮动宽度=300;
对于(int k=0;k<[数组计数];k++)
{
UITextField*textField=[[UITextField alloc]initWithFrame:CGRectMake(x,i*(textFieldHeight+间距)、宽度、textFieldHeight)];
//…您希望对文本字段执行的其他操作
[textFieldArray addObject:textField];
}
当然,您需要设置自己的维度,而不是我的示例中指定的硬编码维度。这应该可以工作,当然,前提是您正在寻找这些维度。祝您好运

float textFieldHeight = 42;
float spacing = 8;
float width = 300;

for(int k = 0; k < [array count]; k++)
{
     UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(x, i*(textFieldHeight + spacing), width, textFieldHeight)];
     // ... other things you'd like to do with the textField
     [textFieldArray addObject:textField];
}