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

  • SEARCH
  • Home
  • 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 8299451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:09:31+00:00 2026-06-08T16:09:31+00:00

I have an array with 20 objects. there can be more objects in that

  • 0

I have an array with 20 objects. there can be more objects in that array. for simplicity reason lets say its only nsstring object in that array.

i want to show 3 of those elements in every row. so number of rows are

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
  int i = 0;

if ( ([myArray count] % 3) > 0 )
{
    i++;
}
return [myArray count] / 3 + i;

}

i have a helper veriable int lastObj=0

    - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
  ---instaniate the cell

   for (int i = 1; i <= 3; i++)
    {
        if (lastObj <= [myArray count])
        {
            --create cell content
            -- cellContent.myLabel.text=[myArray onbjectAtIndex:lastObj]
            --add cellContent to cell 
            lastObj++;

        }
    }
return cell;
}

so if i have 5 objects in that array, then they get displayed properly.
but if it the list has 14 elements then the first 9 elements gets display and it starts from element 0 and the rest dont show up. on the app you can see 3 rows and each have 3 elements of array.
so i’m trying to mimic 3 columns.

any idea how i can resolve this issue?

  • 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-06-08T16:09:33+00:00Added an answer on June 8, 2026 at 4:09 pm

    Try this:

        - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        if (cell == nil)
        {
          ---instaniate the cell
          cell = [[UITableViewCell alloc] init]; //If you don't ARC then retain accordingly. 
    
        }
    
           for (int i = indexPath.row * 3 ; i < indexPath.row * 3 + 3; i++)
            {
    
    
                if (i <= [myArray count])
                {
    
                    --create cell content
                    -- cellContent.myLabel.text=[myArray onbjectAtIndex:i]
                    --add cellContent to cell 
                    //forget about your last object helper. That would not work anyway. 
    
                }
            }
        return cell;
    }
    

    The Point is that cellForRowAtIndexPath is not nessessarily called in a certain sequence. It is rather coincidence that it is called for the first to seventh row from start. Theoretically it could be called in any sequence.
    Think of this:
    Your table has 30 rows. 10 of thes are visible at once.
    At the beginning it is called for row 0 to 9. But understand that as a coincidence. It could be called in any sequence.
    Then the user scrolls for 5 rows. The method is then called for cell 10 to 14. In this case the cells will be re-used. Your if (cell==nil) branch will not be entered.
    Again in a row. Then the user crolls back 2 rows. Next calls of the method would be for row 9 and 8 – in that sequence.

    So do never ever assume a certain sequence here, even if you seem to observe a certain sequence.

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

Sidebar

Related Questions

Lets say that I have an array that I want to convert to a
Is there any way to obtain Object array of Java Bean fields? I have
I have an array of objects and I want to add another object just
I have an array of objects that have QTTime structs as attributes. The objects
I have a set of 2 or more objects that I'd like to order.
If I have a array with objects: $a = array($objA, $objB); (each object has
Is there any method like the array_unique for objects? I have a bunch of
I have an array of pointers to Objective-C objects. These objects have a sort
I have an array made of unlimited number of objects. These objects have the
I have these code in my views.py: array = [] p = Person.objects.filter(client=1,status='Complete').values('name', 'age',

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.