ios - how to add and remove five text field again and again on add and delete button click -


i want add 5 text field add button click array , delete newly added text field delete button click. when click on add button 5 text field added again , again when click on add button work properly. when click on delete button newly added 5 text field deleted not deleted again , again when click on delete button. code

enter code     

-(void)createtextfield // create 5 text field on button click again , again when click { nslog(@"%d",i);

i=i+1; nsarray *array; array=[[nsarray alloc]initwithobjects:@"degree",@"branch",@"passing year",@"grade/%",@"institute", nil];  /* these 5 text field name textfieldarray = [[nsmutablearray alloc] init]; (int k = 0 ; k< [array count]; k++) { } -(void)deletetextfield       // delete last newly add added text field delete button click deleted once not again , again deleted click on {   nslog(@"%lu",(unsigned long)[textfieldarray count]);  int var = [textfieldarray count] - 5; int test = [textfieldarray count];  for(int p = test;p>var;p--) {     nslog(@"%d",i);    [[textfieldarray objectatindex:p-1] removefromsuperview];  /* code remove newly added text field delete button click    [textfieldarray removeobjectatindex:p-1]; } here 

seeing posted code, without description, can assume require code empty loop in createtextfields.

try this:

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 textfield      [textfieldarray addobject:textfield]; } 

of course need set own dimensions, instead of hard coded ones, specified in sample. should work, provided looking for, of course. luck!!


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -