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 6095897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:51:51+00:00 2026-05-23T12:51:51+00:00

I want to make a table view in which i want to show some

  • 0

I want to make a table view in which i want to show some items or images ( 4 items in a row)For eg: If i have 7 images i want to show 4 in first row and 3 in next row and if i have 13 images then it should display like 4,4,4,1 in rows 1,2,3,4 respectively. I have achievd this but my problem is those images keep changing their position (shift from 1 to 3 row and vice versa) when i scroll the table view. Please tell me some way so that my images automatically adjust themselves 4 in a row and does not repeat if i scroll the table view.

My code is:

(array has 7 image-datas stored in it) 


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 93;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [array count];
}


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



    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Avi"];

    for (UIView *view in cell.contentView.subviews) {
        [view removeFromSuperview];
    }
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Avi"] autorelease];
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }


    NSData *imageData;


        for(int i=0;i<4;i++){

        imageData=[array objectAtIndex:indexpath.row];

        UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom];
        Button.frame = CGRectMake(5+(i*77), 5, 77,85);
        [Button setBackgroundImage:[UIImage imageWithData:imageData] forState:UIControlStateNormal];


        [cell.contentView addSubview:Button];


    }

return cell;
  • 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-23T12:51:52+00:00Added an answer on May 23, 2026 at 12:51 pm

    So the code snippet you’ve posted isn’t particularly helpful, but this almost certainly is a case of not recycling your table view cells properly.

    Table views ‘recycle’ their cells for efficiency and performance – when a cell scrolls out of view it is marked for recycling: when you next request a new cell you will be given a recycled cell if one is available (otherwise a new cell will be created).

    If all your cells use the same layout, this isn’t a problem. However, if you adjust the layout of your cells (as you do) this can cause problems, because you might have set up a cell for 2-picture layout and have it be recycled for a 4-picture cell.

    You have two options here: either take care to reset your cells as required (when you request a new cell reset all the view parameters you’ve created, which in your case would be by removing all the superviews), or create different cells with different identifiers for each of your layouts.

    By the way, just looking at your current code it seems like you may want to consider some custom cells. Currently you add new images to the cell’s contents view, which means since you never remove them every time your cell gets recycled more and more and more images get added! It’s quite inefficient. Better to create a cell that has four image views ready to go, and you just assign the image property as required.

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

Sidebar

Related Questions

I have a cell in a static table view which I want selected (highlighted
I want to make a table view in my iPhone Application.. In that table
I want to make an hibernate querycount on a table. I have to values,
I want to make sure I'm not inserting a duplicate row into my table
I have a table : tags(tagname,entryid,stamp) and i want to make a section for
I have a table A with a date field. I want to make a
I have a table with primary key (ColumnA, ColumnB). I want to make a
I have a table generated from database ( basically in MVC view). I want
I have a table view and I want to put a label on the
I have a Navigation View with a Table View, when a row is clicked,

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.