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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:33:10+00:00 2026-06-15T09:33:10+00:00

trying to load an image inside a cell. i am able to load the

  • 0

trying to load an image inside a cell.
i am able to load the image inside the cell but when scrolling up and down the tableView the image appears randomly inside other different cells as well…

here is some code:

- (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";


UITableViewCell *cell = [tableView_ dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];

    cell.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.textColor = [UIColor whiteColor];


}

if (indexPath.section == ONE_SECTION) {

    switch(indexPath.row) {

        case 0:{
            //some code
}
                break;
            case 2:{
                              //some code

}
                break;
            case 3:{


            UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(256,0,43,43)];
            imageView.contentMode = UIViewContentModeScaleAspectFit;
            [cell.contentView addSubview:imageView];
            imageView.layer.cornerRadius = 10.0;
            //imageView.contentMode = UIViewContentModeScaleAspectFit;
            imageView.layer.masksToBounds = YES;
            imageView.image = [UIImage imageNamed:@"imageName.png"];}
            break;
        default:
            break;
    }

}

if (indexPath.section == TWO_SECTION) {
    //some code
}

if (indexPath.section == THREE_SECTION) {
    //some code
}


return cell;
}

thank you

  • 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-15T09:33:11+00:00Added an answer on June 15, 2026 at 9:33 am

    Try with the below code. If you are reusing cells, you dont have to add imageView repeatedly to all cells. You can create it in cell allocation part and just set imageView.image property out side it as shown below.

    - (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView_ dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];
    
        cell.backgroundColor = [UIColor clearColor];
        cell.detailTextLabel.textColor = [UIColor whiteColor];
    
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(256,0,43,43)];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [cell.contentView addSubview:imageView];
        imageView.layer.cornerRadius = 10.0;
        //imageView.contentMode = UIViewContentModeScaleAspectFit;
        imageView.layer.masksToBounds = YES;
        imageView.tag = 567; //unique tag
    }
    
    UIImageView *imageView = (UIImageView *)[cell.contentView viewWithTag:567];
    imageView.image = nil;
    
    if (indexPath.section == ONE_SECTION) {
    
        switch(indexPath.row) {
    
            case 0:{
                //some code
            }
            break;
            case 2:{
                                  //some code
            }
            break;
            case 3:{
    
                UIImageView *imageView = (UIImageView *)[cell.contentView viewWithTag:567];
                imageView.image = [UIImage imageNamed:@"imageName.png"];
            }
                break;
            default:
                break;
        }
    }
    
    if (indexPath.section == TWO_SECTION) {
        //some code
    }
    
    if (indexPath.section == THREE_SECTION) {
        //some code
    }
    
     return cell;
    }
    

    A better approach is to create custom UITableViewCell class and add UIImageView inside the init method of that cell. Then set the property as cell.imageView.image = ... in cellForRowAtIndexPath method.

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

Sidebar

Related Questions

I am trying to load an image inside a function, but the image is
I'm trying to load image from a plist to a custom cell. It all
I am trying to load an image but it is showing the error message
I am trying to load an image in memory but might have memory issues
I'm trying to load an image through PHP, but I don't know how. The
I am trying to load the image in the following way. But when I
I am trying to lazy load the Image Source for the Image Control but
I am trying to use 'Universal Image Loader' to load images inside of my
I'm trying to load an image from a url inside of drawRect: . Our
I am trying to load a binary image file to do some processing inside

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.