Here is a link with with an image of the big button. The red image with number 0 over it is a textField where my problem is present.

I have a scroll View having 12 (big)buttons that were created programmatically. On those buttons u have added 12 more buttons(one small button on each big button) and the code was working fine. But when i tried to add 12 textFields as subview, one on each big button programmatically i am unable to get twelve textFields. I end up getting just one textField and that too always on the last button of a particular row of big buttons. I am unable to identify the issue. Here is my code to create the big buttons, small buttons and the textFields on them.
- (void)createButtons{
NSUInteger i;
int xCoord=54;
int yCoord=10;
int buttonWidth=292;
int buttonHeight=266;
int buttonGap = 80;
int count=1;
UIButton *aButton;
//forCartButton
int xCoordForCart=230;
int yCoordForCart=200;
int buttonWidthForCart=35;
int buttonHeightForCart=36;
int buttonGapForCart = 160;
UIButton *aButtonForCart;
//for textField
int xCoordForTextField=aButton.frame.origin.x-30;
int yCoordForTextField=aButton.frame.origin.y+210;
int WidthForTextField=50;
int HeightForTextField=30;
int GapForTextField= 160;
UITextField *textField=[[UITextField alloc]init];
[textField setBorderStyle:UITextBorderStyleRoundedRect];
textField.layer.cornerRadius = 15.0;
textField.text=@"24";
textField.backgroundColor = [UIColor redColor];
textField.borderStyle = UITextBorderStyleRoundedRect;
for (i = 0; i <= 11; i++)
{
aButton = [UIButton buttonWithType:UIButtonTypeCustom];
aButtonForCart = [UIButton buttonWithType:UIButtonTypeCustom];
if(count >=1 && count<=3){
//for item button
aButton.frame = CGRectMake(xCoord, yCoord,buttonWidth,buttonHeight);
xCoord=xCoord+323;
//for cart button
aButtonForCart.frame = CGRectMake(xCoordForCart, yCoordForCart,buttonWidthForCart,buttonHeightForCart);
xCoordForCart=xCoordForCart+2;
//for textField
textField.frame = CGRectMake(xCoordForTextField+50,yCoordForTextField,WidthForTextField,HeightForTextField);
xCoordForTextField = xCoordForTextField+10;
[aButton addSubview:textField];
[aButton bringSubviewToFront:textField];
if(count == 3){
xCoord=54;
xCoordForCart=230;
xCoordForTextField = 230;
}
}else if (count >3 && count<=6){
yCoord=buttonHeight+buttonGap;
aButton.frame= CGRectMake(xCoord, yCoord,buttonWidth,buttonHeight);
xCoord=xCoord+323;
//for cart button
yCoordForCart=buttonHeightForCart+buttonGapForCart;
aButtonForCart.frame= CGRectMake(xCoordForCart, yCoordForCart,buttonWidthForCart,buttonHeightForCart);
xCoordForCart=xCoordForCart+2;
//for TextField
textField.frame = CGRectMake(xCoordForTextField+50,yCoordForTextField,WidthForTextField,HeightForTextField);
xCoordForTextField = xCoordForTextField+10;
[aButton addSubview:textField];
[aButton bringSubviewToFront:textField];
if(count == 6){
xCoord=54;
xCoordForCart=230;
xCoordForTextField = 230;
}
}else if (count >6 && count<=9){
yCoord=buttonHeight+buttonHeight+buttonGap+30;
aButton.frame= CGRectMake(xCoord, yCoord,buttonWidth,buttonHeight);
xCoord=xCoord+323;
//for cart button
yCoordForCart=buttonHeightForCart+buttonHeightForCart+buttonGapForCart-30;
aButtonForCart.frame= CGRectMake(xCoordForCart, yCoordForCart,buttonWidthForCart,buttonHeightForCart);
xCoordForCart=xCoordForCart+2;
//for textField
textField.frame = CGRectMake(xCoordForTextField+50,yCoordForTextField,WidthForTextField,HeightForTextField);
xCoordForTextField = xCoordForTextField+10;
[aButton addSubview:textField];
[aButton bringSubviewToFront:textField];
if(count == 9){
xCoord=54;
xCoordForCart=230;
xCoordForTextField = 230;
}
}else if (count >9 && count<=12){
yCoord=buttonHeight+buttonHeight+buttonHeight+buttonGap+60;
aButton.frame= CGRectMake(xCoord, yCoord,buttonWidth,buttonHeight);
xCoord=xCoord+323;
//for cart button
yCoordForCart=buttonHeightForCart+buttonHeightForCart+buttonGapForCart-30;
aButtonForCart.frame= CGRectMake(xCoordForCart, yCoordForCart,buttonWidthForCart,buttonHeightForCart);
xCoordForCart=xCoordForCart+2;
//for textField
textField.frame = CGRectMake(xCoordForTextField+50,yCoordForTextField,WidthForTextField,HeightForTextField);
xCoordForTextField = xCoordForTextField+10;
[aButton addSubview:textField];
[aButton bringSubviewToFront:textField];
if(count == 12){
xCoord=54;
xCoordForCart=230;
xCoordForTextField = 230;
}
}
count++;
[aButton setTag:i];
[aButtonForCart setTag:i];
[aButtonForCart setImage:[UIImage imageNamed:@"cart_red.png"] forState:UIControlStateNormal];
[aButton setImage:[UIImage imageNamed:[self.imgNames objectAtIndex:i]] forState:UIControlStateNormal];
[aButton addSubview:aButtonForCart];
[self.scrollViewForCatlogView addSubview:aButton];
//selectors
[textField addTarget:self action:@selector(textFieldTouched:) forControlEvents:UIControlEventTouchDown];
[aButton addTarget:self action:@selector(itemButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[aButtonForCart addTarget:self action:@selector(cartButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
}
[self.scrollViewForCatlogView setContentSize:CGSizeMake(900, yCoord+buttonHeight)];
}
I have seen these questions but they weren't useful in my case
1) dynamically create multiple TextFields based on array.length