Objective c 目标C:逻辑问题

Objective c 目标C:逻辑问题,objective-c,Objective C,嘿,伙计们,我这里有点麻烦。我有一个使网格显示的视图。我的意思是,我有9个项目和集合,每行显示3个。结果是3行。没关系。我不明白的是,这就是为什么我总是在他们之间留有空间。有时它会出现在队伍中间。空间等于一行的高度 检查代码: NSInteger quantidadeDeVideos = [self.videosURL count]; NSInteger contadorDeVideos = 0; NSInteger idLinha = 0; NSInteger linha = 1; NSIn

嘿,伙计们,我这里有点麻烦。我有一个使网格显示的视图。我的意思是,我有9个项目和集合,每行显示3个。结果是3行。没关系。我不明白的是,这就是为什么我总是在他们之间留有空间。有时它会出现在队伍中间。空间等于一行的高度

检查代码:

NSInteger quantidadeDeVideos = [self.videosURL count];
NSInteger contadorDeVideos = 0;

NSInteger idLinha = 0;
NSInteger linha = 1;
NSInteger itemq = 0;

while (contadorDeVideos < quantidadeDeVideos) {

    float f;
    float g;

    // Set the lines

    if (itemq < 3) {
        itemq++;
    }
    else {
        itemq = 1;
        linha++;
    }

    // This makes the second line multiplies for 150;
    if (linha > 1) {
        g = 150;
    }
    else {
        g = 0;
    }


    // Ignore this, this is foi make 1,2,3. Making space between the itens.

    if (idLinha > 2) {
        idLinha = 0;
    }


    NSLog(@"%i", foi);

    float e = idLinha*250+15;
    f = linha*g;

    UIImageView *thumbItem = [[UIImageView alloc] init];
    thumbItem.frame = CGRectMake(e, f, 231, 140);

    UIColor *bkgColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"VideosItemBackground.png"]];
    thumbItem.backgroundColor = bkgColor;
    thumbItem.opaque = NO;

    [self.videosScroll addSubview:thumbItem];

    contadorDeVideos++;
    idLinha++;

}
NSInteger quantidadevideos=[self.videosURL count];
NSInteger CONTADODEVIOS=0;
NSInteger-idLinha=0;
NSInteger-linha=1;
NSInteger itemq=0;
while(contadoradevideos1){
g=150;
}
否则{
g=0;
}
//忽略这个,这是foi制造1,2,3。在ITEN之间制造空间。
如果(idLinha>2){
idLinha=0;
}
NSLog(@“%i”,foi);
浮子e=idLinha*250+15;
f=林哈*g;
UIImageView*thumbItem=[[UIImageView alloc]init];
thumbItem.frame=CGRectMake(e,f,231140);
UIColor*BKGCLOR=[[UIColor alloc]initWithPatternImage:[UIImage IMAGENAME:@“VideosItemBackground.png”];
thumbItem.backgroundColor=bkgColor;
thumbItem.不透明=否;
[self.videosScroll addSubview:thumbItem];
ContadorDeviceOS++;
idLinha++;
}
这一结果应该是:

[]
[]
[…]

这就是我得到的:

[]

[]
[…]


谢谢大家

linha
为1时,
g
为0,使
linha*g
0。对于后续行,
g
为150,使得第二次迭代的
linha*g
==300(比第一次跳300),之后每次增加150。不要每次都有条件地设置
g
,只需将其设为常数150,然后使用
(linha-1)*g
作为
f
的值,或者只需在0处启动
linha

如果您想了解如何自己发现问题:

  • 问问自己,这里出了什么问题

    • 矩形画得太低了一行
    • 它只发生在第一排之后
  • 我们看一看画矩形的那条线:

    thumbItem.frame = CGRectMake(e, f, 231, 140)
    
  • 变量
    f
    是y坐标。这一定是搞砸了。让我们看看
    f
    是如何定义的:

    f = linha*g;
    
    if (linha > 1) {
        g = 150;
    }
    else {
        g = 0;
    }
    
  • 好的,
    linha
    是行号,在循环中只更改一次,没有任何条件逻辑。所以问题可能是
    g
    。让我们来看看这一点是如何定义的:

    f = linha*g;
    
    if (linha > 1) {
        g = 150;
    }
    else {
        g = 0;
    }
    
  • 嘿,
    g
    在第一次迭代后发生了变化——这正是我们的问题出现的时候。让我们看看
    linha*g
    的值是什么:

    1 * 0 = 0
    2 * 150 = 300 (+300)
    3 * 150 = 450 (+150)
    4 * 150 = 600 (+150)
    

  • 啊哈-问题是在第一次迭代中将
    g
    设置为0会破坏模式。

    linha
    为1时,
    g
    为0,使
    linha*g
    0。对于后续行,
    g
    为150,使得第二次迭代的
    linha*g
    ==300(比第一次跳300),之后每次增加150。不要每次都有条件地设置
    g
    ,只需将其设为常数150,然后使用
    (linha-1)*g
    作为
    f
    的值,或者只需在0处启动
    linha

    如果您想了解如何自己发现问题:

  • 问问自己,这里出了什么问题

    • 矩形画得太低了一行
    • 它只发生在第一排之后
  • 我们看一看画矩形的那条线:

    thumbItem.frame = CGRectMake(e, f, 231, 140)
    
  • 变量
    f
    是y坐标。这一定是搞砸了。让我们看看
    f
    是如何定义的:

    f = linha*g;
    
    if (linha > 1) {
        g = 150;
    }
    else {
        g = 0;
    }
    
  • 好的,
    linha
    是行号,在循环中只更改一次,没有任何条件逻辑。所以问题可能是
    g
    。让我们来看看这一点是如何定义的:

    f = linha*g;
    
    if (linha > 1) {
        g = 150;
    }
    else {
        g = 0;
    }
    
  • 嘿,
    g
    在第一次迭代后发生了变化——这正是我们的问题出现的时候。让我们看看
    linha*g
    的值是什么:

    1 * 0 = 0
    2 * 150 = 300 (+300)
    3 * 150 = 450 (+150)
    4 * 150 = 600 (+150)
    
  • 啊哈-问题是在第一次迭代中将
    g
    设置为0会破坏模式