objective c - Access text values from dynamically created UITextFields. iOS -
objective c - Access text values from dynamically created UITextFields. iOS -
i creating uitextfield
's in view based on count of nsarray
.
i want know how can access text values based on tag of uitextfield
in nsarray
.
so after add together below uitextfield
's view how write code retrieve .text values mytextfield0, mytextfield1 , mytextfield2 respectively?
example:
nsstring *textfeildtextstring = [nsstring stringwithformat:@"%@",mytextfield1.text];
actual code:
self.textfieldarray = [nsarray arraywithobjects:@"one", @"two", @"three",nil]; nsmutabledictionary *mydict = [nsmutabledictionary dictionary]; (int i=0; i<[self.textfieldarray count]; i++) { uiview *spacerview1 = [[uiview alloc] initwithframe:cgrectmake(0, 0, 10, 10)]; uitextfield *mytextfield = [[uitextfield alloc]initwithframe:cgrectmake(20, 60*i+150, 280, 45)]; mytextfield.borderstyle = uitextborderstylenone; mytextfield.font = [uifont systemfontofsize:14]; mytextfield.returnkeytype = uireturnkeydefault; mytextfield.placeholder = nslocalizedstring(@"answer", nil); mytextfield.inputaccessoryview = [super createinputtoolbar]; mytextfield.background = [uiimage imagenamed:@"textfieldbg"]; mytextfield.textcolor = [uicolor apptextcolorgrey]; [mytextfield setleftview: spacerview1]; mytextfield.leftviewmode = uitextfieldviewmodealways; mytextfield.delegate = self; mytextfield.tag = 200+i; [mydict setobject:mytextfield forkey:[nsstring stringwithformat:@"mytextfield%d", i]]; [self.view addsubview:mytextfield]; } nslog(@"dict: %@",mydict);
the nslog of uitexfields
2014-10-31 11:58:32.715 [51992:13536821] dict: { mytextfield0 = "<uitextfield: 0x7faea14f8430; frame = (20 150; 280 45); text = ''; clipstobounds = yes; opaque = no; tag = 200; layer = <calayer: 0x7faea14f82d0>>"; mytextfield1 = "<uitextfield: 0x7faea14fae70; frame = (20 210; 280 45); text = ''; clipstobounds = yes; opaque = no; tag = 201; layer = <calayer: 0x7faea14faca0>>"; mytextfield2 = "<uitextfield: 0x7faea16dce30; frame = (20 270; 280 45); text = ''; clipstobounds = yes; opaque = no; tag = 202; layer = <calayer: 0x7faea16d19c0>>";
}
for (int i=0; i<[self.textfieldarray count]; i++) { uitextfield *txt = (uitextfield *)[mydict objectforkey:[nsstring stringwithformat:@"mytextfield%d", i]]; nslog(@"text %@",txt.text); }
ios objective-c uitextfield nsarray nsdictionary
Comments
Post a Comment