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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:56:45+00:00 2026-05-22T02:56:45+00:00

I need to draw an image in a table cell. So far I have

  • 0

I need to draw an image in a table cell. So far I have not been able to get a proper reference to the UIImageView after I create the view and assign it to the cell. The same procedure does work for a UILabel, for example.

I can’t figure out what I’m doing wrong.

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

    UIImageView *imageView;
    UILabel *title;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                       reuseIdentifier:CellIdentifier] autorelease];

        // Setup title
        title = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)] autorelease];
        title.tag = 1;
        [cell.contentView addSubview:title];

        // Setup image
        UIImageView* imageView = [[[ UIImageView alloc] initWithFrame: 
                                   CGRectMake(50, 0, 50, 50)] autorelease];
        imageView.tag = 2;
        [cell.contentView addSubview:imageView];

    } else {
        // Get references to cell views
        title = (UILabel *)[cell.contentView viewWithTag:1];
        imageView = (UIImageView *)[cell.contentView viewWithTag:2];
    }

    NSLog(@"%@", [title class]);     // UILabel
    NSLog(@"%@", [imageView class]); // CRASH! EXC_BAD_ACCESS

    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-22T02:56:46+00:00Added an answer on May 22, 2026 at 2:56 am

    The problem is the scope of the imageView variables. In the case that the cell doesn’t exist yet, you create a new UIImageView that only exists in the if-block. It hides the variable that you declared earlier and disappears after the if-block ends.
    Instead of

    UIImageView *imageView = ...
    

    you should simply write

    imageView = ...
    

    Otherwise you’re creating a new object that has nothing to do with the object you declared at the top of the method and the original imageView is still undefined.

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

Sidebar

Related Questions

I need to draw a .png image on an UIView. I have no clue
I have a raw image buffer in the RGB format. I need to draw
I have a table of canvas elements that emulates tiled image. I need to
I need to draw on a TPanel, ideally directly so I don't have another
I need to draw such a image like like.. a + mark at centre
I have problem to draw line on scaled and transformed image on canvas, well
Need draw a graph with dot/graphviz like this image: The texts can be above
I need to create a web page where i can draw a image using
Need your help on the below. I have a table where I have functions
i need to draw something like the image below using WPF... i need this

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.