I have this code:
//Value of userCount is 25
auxCount = 0;
for (int y_axis=0; y_axis<=8; y_axis++) //ROWS
{
for (int x_axis=0; x_axis<=2; x_axis++) //COLUMNS
{
if (auxCount<userCount) {
NSLog(@"auxCount: %i\n",auxCount);
NSLog(@"userCount: %i\n\n",userCount);
UIButton *btn= [[UIButton alloc] initWithFrame:CGRectMake(16+100*x_axis,115.0*y_axis,88.0 ,88.0)];
UILabel *userLabel = [[UILabel alloc] initWithFrame:CGRectMake(16+100*x_axis,90+115.0*y_axis, 88.0, 15.0)];
userLabel.textAlignment = UITextAlignmentCenter;
userLabel.text = mensaje;
btn.backgroundColor=[UIColor groupTableViewBackgroundColor];
[scrollViewUsers addSubview:btn];
[scrollViewUsers addSubview:userLabel];
auxCount++;
}
}
}
With this I want a matrix with 3 columns and X rows, but only displays 3 rows and the third row only displays 1 button. And in Debug area appears:
auxCount: 0
userCount: 25
auxCount: 4
userCount: 25
auxCount: 8
userCount: 25
auxCount: 12
userCount: 25
auxCount: 16
userCount: 25
auxCount: 20
userCount: 25
auxCount: 24
userCount: 25
auxCount increments by 4 by 4. I think that is because the if instructions are executed only by the first for loop but I don’t know why.
Please, I need your help.
ps: sorry for my english!!
just try this for loops as i have used in my app it worked for me.
to find out the number of rows depending on number of columns and total count
here
ris for number if row[dao libraryCountis total number of items andkColis fix number of column for you it is 3 andkDis same askColonly deference is it is type of float ie 3.0 in your casethen use the for loop as below
for
auxCountuse this codeput this in side both
forloop instead of using++just change the both
forloops and replaceifcondition with appropriate variablesEnjoy Coding 🙂
And Good Luck
any help is needed just comment me i will love to help you