嘿家伙,我在这里遇到了一些麻烦。我有一个使网格显示的视图。我的意思是,我有9个项目并设置每行显示3个。导致3行。没关系。我没有理解,这就是为什么我总能在他们之间找到空间。有时会出现在线条中间。该空间等于一行高度。Objective-C:逻辑问题
检查代码:
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++;
}
这是结果应该是:
[] [] []
[] [] []
[] [] []
这就是我得到的:
[] [] []
[] [] []
[] [] []
谢谢大家!
哦,他的工作!我只是没有看到这一点。非常感谢! – 2011-03-09 02:56:28
+1很好的解释。 – 2011-03-09 05:17:14