嘿傢伙,我在這裏遇到了一些麻煩。我有一個使網格顯示的視圖。我的意思是,我有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