Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4040260
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:43:48+00:00 2026-05-20T12:43:48+00:00

Hey guys, I’m getting a little trouble here. I have a view that makes

  • 0

Hey guys, I’m getting a little trouble here. I have a view that makes a grid display. I mean, I have 9 items and sets to display 3 per line. Resulting in 3 lines. That’s OK. What I don’t understang, it’s why always I get a space between them. Sometimes it comes up and on the middle of the lines. The space is equal to one line height.

Check the code:

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++;

}

This is the result should be:

[][][]
[][][]
[][][]

And this is what I’m getting:

[][][]

[][][]
[][][]

Thanks for all!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:43:49+00:00Added an answer on May 20, 2026 at 12:43 pm

    When linha is 1, g is 0, making linha * g 0. For the subsequent lines, g is 150, making linha * g == 300 for the second iteration (a jump of 300 over the first), after which it increases by 150 each time. Instead of conditionally setting g each time through, you should just make it a constant 150 and then either use (linha - 1) * g for the value of f or just start linha at 0.

    If you want to see how to spot the problem yourself:

    1. Ask yourself, what is going wrong here?

      • The rectangles are being drawn one row too low
      • It only happens after the first row
    2. So we look at the line that’s responsible for where the rectangles are drawn:

      thumbItem.frame = CGRectMake(e, f, 231, 140)
      
    3. The variable f is the y-coordinate. This has to be what’s messed up. Let’s see how f is defined:

      f = linha*g;
      
    4. OK, linha is the line number and it’s only changed once in the loop without any conditional logic. So the problem is probably g. Let’s see how that one is defined:

      if (linha > 1) {
          g = 150;
      }
      else {
          g = 0;
      }
      
    5. Hey, g changes after the first iteration — precisely when our problem crops up. Let’s see what the values of linha*g are:

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

    Ah-ha — the problem is that setting g to 0 on the first iteration breaks the pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys, i'm getting an exception on the following inner exception: {Value cannot be
Hey guys i wrote a quick test. I want delete to call deleteMe which
Hey peoples, I've been studying Java for a couple of weeks, and have decided
Hey right now I'm using jQuery and I have some global variables to hold
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey so what I want to do is snag the content for the first
Hey, I'm using Levenshteins algorithm to get distance between source and target string. also
Hey all, my Computational Science course this semester is entirely in Java. I was
Hey, I've been developing an application in the windows console with Java, and want
Hey all. Newbie question time. I'm trying to setup JMXQuery to connect to my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.