iphone - fetching textfield.text values from dynamically generated textfields -
i new world of objective c
generating dynamic textfields
, trying fetch .text value each textfield
on button press problem facing value in last textfield
fetched eg- if 3 dynamic textfeilds
generated , enter values 1,2,3 in textfeilds
respectively want these values getting value last textfeild
the code trying below //this function generates dynamic textfeilds
- (void)dynamictextboxes { nsstring *string = txt1.text; int pointsvalue = [string intvalue]; int x; (x=0; x < pointsvalue ; x++) { txtfldframe1 = [[uitextfield alloc] initwithframe:cgrectmake(100,60*x,120,45)]; txtfldframe1.borderstyle=uitextborderstyleroundedrect; txtfldframe1.keyboardtype=uikeyboardtypenumberpad; [self.view addsubview:txtfldframe1]; arrput=[[nsmutablearray alloc]initwithobjects:txtfldframe1, nil]; } } // function acess values nsstring *string = txt1.text; int pointsvalue = [string intvalue]; int x; (x=0; x < pointsvalue ; x++) { nsstring * values=txtfldframe1.text; [arrput addobject:values]; if(txtfldframe1.text.length>0) { arrclick=[nsmutablearray array]; [arrclick addobjectsfromarray:arrput]; } } nslog(@"%@",arrclick);
can me out in advance
- (void)viewdidload { [super viewdidload]; [self dynamictextfields]; } - (void)dynamictextfields { nsstring *string = @"3"; int pointsvalue = [string intvalue]; int x; (x=1; x < pointsvalue ; x++) { uitextfield *textfield = [[uitextfield alloc] initwithframe:cgrectmake(100,60*x,120,45)]; textfield.borderstyle=uitextborderstyleroundedrect; [textfield setdelegate:self]; textfield.keyboardtype=uikeyboardtypenumberpad; textfield.tag = x; [self.view addsubview:textfield]; } } - (ibaction)btnretrievetextfeildvalues:(id)sender { nsmutablearray *valuesarray = [[nsmutablearray alloc]init]; nsstring *string = @"3"; int pointsvalue = [string intvalue]; int x; (x=1; x < pointsvalue ; x++) { uitextfield *textfield = (uitextfield *)[self.view viewwithtag:x]; nslog(@"text - -%@",textfield.text); if ([textfield.text length]!=0) { [valuesarray addobject:textfield.text]; } } nslog(@"valuesarray -- %@",valuesarray); }
Comments
Post a Comment