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

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

node.js - Express and Redis - If session exists for this user, don't allow access -