Reputation: 1091
I am creating an iPad app, in this I am dynamically creating the interface in the device, here is the code.
- (void)setUpInterface{
UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 10,self.view.frame.size.width-20, self.view.frame.size.height-20)];
int y = 0;
for (int i=0; i < [labelArray count]; i++) {
y=y+75;
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, y, 500, 30)];
label.text = [NSString stringWithFormat:@"%@",[labelArray objectAtIndex:i]];
label.backgroundColor = [UIColor clearColor];
label.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
[scrollview addSubview:label];
UITextField *textBox = [[UITextField alloc]initWithFrame:CGRectMake(200, y, 500, 30)];
textBox.borderStyle = UITextBorderStyleRoundedRect;
textBox.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
[scrollview addSubview:textBox];
}
scrollview.contentSize = CGSizeMake(self.view.frame.size.width-100, y*2);
scrollview.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
scrollview.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:scrollview];
}
At the end when I click on a button I want to get the data entered in each text box separately. How can I implement that? How to assign names to each objects? Thanks.
Upvotes: 0
Views: 513
Reputation: 8106
for (UITextField *textField in [self.scrollview subviews])
{
if([textField isKindOfClass:[UITextField class]])
{
NSLog(@"text == %@", textField.text);
}
}
Upvotes: 2
Reputation: 146
You can use the tag property. ie:
textBox.tag = 1;
textBox.tag = 2;
etc.
Unfortunately, these have to be integers, but you can make a map of integers to names if you want.
Upvotes: 0