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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:29:31+00:00 2026-05-23T10:29:31+00:00

I am using these following codes to display multiple images on a table view.

  • 0

I am using these following codes to display multiple images on a table view. One row need to display 4 only images

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

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

    //Resize auto complete table based on how many elements will be displayed in the table
    return (int)ceil([wordsInSentence count]/4.0);
}


-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"entered forRowAtIndexPath");
    if ((indexPath.row % 2) == 0) {

        cell.backgroundColor = [UIColor whiteColor];

    }
    else {

        cell.backgroundColor = [UIColor whiteColor];
    }

}

On the button click wich will display table view I wrote the below code

-(IBAction)setImageOnTableView
{
    NSLog(@"entered setImageOnTableView");
    j=1;

    tableView.hidden=NO;

    //Breaking the sentence into words and then placing it in an array
    wordsInSentence=[[youSaid.text uppercaseString] componentsSeparatedByString:@" "];
    [wordsInSentence retain];
    [youSaid resignFirstResponder];

    [tableView reloadData];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;
    NSLog(@"entered cellForRowAtIndexPath");
    //j=1;
    static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier";
    cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AutoCompleteRowIdentifier] autorelease];

        [cell.contentView addSubview:nil];

        for (int i=0; i <= [wordsInSentence count]; ++i) {
            UIImageView *imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(30+90*(i%4), 20, 70, 100)] autorelease] ;
            imageView1.tag = i+1;
            [imageViewArray insertObject:imageView1 atIndex:i];
            [cell.contentView addSubview:imageView1];
            //[imageView1 release];
          }    
    }

    int photosInRow;
    if ( (indexPath.row < [tableView numberOfRowsInSection:indexPath.section] - 1) || ([wordsInSentence count] % 4 == 0) ) {
        photosInRow = 4;
    } else {
        photosInRow = [wordsInSentence count] % 4;
    }

    for ( int i = 1; i <=photosInRow ; i++ ){            
        imageView = (UIImageView *)[cell.contentView viewWithTag:j];
        [self **showImage**:imageView];

    }
    return cell;
}


//method used to show the images on the table view by checking the category 
//and images in the category
-(void)**showImage**:(UIImageView *)imageView
{
    NSLog(@"entered showImage");

//this method will check if more than 1 image is present in the category    
    if([self searchImagesInSameCategory:[wordsInSentence objectAtIndex:j-1]]>1)
    {
        UIButton *descriptiveButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [descriptiveButton setFrame:CGRectMake(50, 0, 30, 30)];
        [imageView setUserInteractionEnabled:TRUE];

        [descriptiveButton addTarget:self action:@selector(showPopOver1:) forControlEvents:UIControlEventTouchUpInside];
        descriptiveButton.tag=j;
        [imageView addSubview:descriptiveButton];
        globalString=[wordsInSentence objectAtIndex:j-1];
    }
}

In this code when I displayed 4 images it will display 4. If I displayed 3 images after displaying 4 images, 3 images are displaying but still 4 th image is presenting in table view. How can I fix this. Please can any one help me…

The main problem is, an image view that displayed before is not removing from the 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-23T10:29:31+00:00Added an answer on May 23, 2026 at 10:29 am

    Table cells can be (and in your code, are) cached and reused – which means that for every call to cellForRowAtIndexPath:: you should make sure that the cell you are returning is correct (has the correct images). In your case, I would simply clear the cell of all subviews/image views and recreate them for every fetch.

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

Sidebar

Related Questions

Currently i'm using these codes to save my images into NSDocumentDirectory. I use this
Hi there im using the following code for insert text and images, but I
I'm using the following code to display two div containers after 3 minutes: /*
I'm using the following code to display a YouTube video. <object width=425 height=344> <param
How can i generate multiple texts using the imagecreatetruecolor() method? I have the following
The tooltips can be set to display percentages using the following code: var formatter
Anyone out there using the FTUtils library for iPhone development? Following the instructions here
Is there a way to do the following using LINQ? foreach (var c in
I was thinking of using these styles for easier cell rollover effects in a
Has anyone had experience using these two technologies in tandem? What are (if any)

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.