Iphone 在另一个循环中循环
我有以下代码:Iphone 在另一个循环中循环,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,我有以下代码: //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(@"aux
//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++;
}
}
}
//userCount的值是25
auxCount=0;
对于(int y_axis=0;y_axis,只需在循环中尝试这个,因为我在应用程序中使用了它,它对我有效
根据列数和总计数找出行数
int r;
float rem = [dao libraryCount] % kCol;
if(rem == 0.0f)
r = floor([dao libraryCount]/kD);
else
r = ceil([dao libraryCount]/kD);
这里的r
表示数字,如果行[dao libraryCount
是项目的总数,kCol
是您的固定列数,它是3,kD
与kCol
相同,唯一不同的是它是浮点型ie 3.0
然后使用for循环,如下所示
for (int row = 0; row < r; ++row)
{
for (int col = 0; col < kCol; ++col)
{
//Your Code to display or any thing
}
}
将其放在两侧的循环中,而不是使用++
只需更改for
循环的,并用适当的变量替换if
条件
享受编码:)
祝你好运
需要任何帮助,请评论我,我很乐意帮助你这里似乎工作得很好。你确定你没有在其他地方更改某些值吗?是的,我确定。auxCount和userCount仅用于此代码我不确定我是否理解,但我会尝试实现它
int index = (row * kCol) + col;
if(index < [dao libraryCount])
{
//Your Code to display or any thing
}