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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:37:47+00:00 2026-05-25T11:37:47+00:00

For an iPhone app I am developing I need to assign custom uitableviewcell images

  • 0

For an iPhone app I am developing I need to assign custom uitableviewcell images based on the integers of arbitrary items in an array. I noticed while doing some testing that indexPath of row only returns indices for the view shown, so basically I need to know how to take an array, of arbitrary size, let’s say right now it has 10 items, and those 10 items are in a table, each item a cell, I need each item to have an index like item 1 is index 0, item 2 is index 1 and so on. So my code would read, if the index == 0, then display this image in the cell, if the index != 0 then display another. I tried that but like I said if I scrolled to the bottom of my tableview it would reassign whichever table item is at the top of the view to 0, so as I scrolled the images kept changing. So basically i need help assigning the images based on an index in my array rather than on the index of the table.

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

    static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {  
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier] autorelease];  
    }

    cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
    cell.detailTextLabel.numberOfLines = 1;
    cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;

    NSString *title =[[stories objectAtIndex: indexPath.row] objectForKey: @"summary"];
    NSString *title2 =[[stories objectAtIndex: indexPath.row] objectForKey: @"title"];
    NSString *dayOfMonthString = [title substringWithRange: NSMakeRange(2, 2)];
    int dateChooser = [dayOfMonthString intValue];

    NSString *monthString = [title substringWithRange: NSMakeRange(0, 2)];

    int monthChooser = [monthString intValue];
    cell.textLabel.text =title2;


    cell.imageView.image = 
    [UIImage imageNamed: [NSString stringWithFormat: @"cal%d.png", dateChooser]];

    if (monthChooser == 1 && (INDEX COMPARISON CODE???){
        UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Jan1.png"]];
        [cell setBackgroundView:myImageView];
    }
  • 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-25T11:37:48+00:00Added an answer on May 25, 2026 at 11:37 am

    Your problem is not getting the right index for the right cell. The row property of the indexPath do correspond to the index of the cell in the whole list of cells, not the index of the visible cells only, so exactly as you expected initially.

    I bet your problem is that you don’t use the reuse mechanism of UITableViewCells correctly
    .
    When you scroll in your TableView, UITableViewCells that are not on screen anymore are “recycled” and reused to display new cells onscreen, in order to avoid too much allocations and useless initializations that would else slow down the scrolling of your tableView.

    The correct code pattern for returning a cell is the following:

    -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
    {
        // Try to retrieve a previously created cell that is not used anymore
        // That's the "recycling" part, we try to reuse a cell instead of creating a new one if possible
        UITableViewCell* cell = [tableView dequeueCellWithIdentifier:@"myIdentifier"];
    
        if (cell == nil)
        {
            // We failed to recycle a previously created cell, so we have no choice to allocate a new one
            cell = [[[UITableViewCell alloc] initWithStyle:... reuseIdentifier:@"myIdentifier"] autorelase];
            // As we just created the cell, we configure everything that will be common to every cell
            // and that won't change even if the cell is reused later when you scroll
    
            // e.g. text color, text font, accessoryType, ...
            cell.textLabel.textColor = [UIColor blueColor];
            ...
        }
    
        // Now we got here either with a brand new cell that have just been created…
        // … or after reusing an old cell that were not onscreen and has been recycled
        // So THIS IS THE PLACE to configure everything that is SPECIFIC to each cell
    
        // namely cell text, especially
        cell.textLabel.text = [yourDataArray objectAtIndex: indexPath.row];
    
    
        return cell;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an iPhone app that features a tab-bar based navigation with five tabs.
In an iPhone app I'm developing, I need to send an email programmatically (read,
We are developing an iPhone app where we need to allow users to search
I am developing a iPhone app using Monotouch. I need to access a Sqlite
I am developing an app where iphone and android phones need to send requests
I'm developing a iPhone app and need to send it to my client. In
I am developing an iPhone app where I don’t want/need the multitasking capability and
I am developing an iPhone app which is a Navigation based app. In this
I am developing iPhone app where I need to provide integration with different social
I'm in the middle of developing a Twitter app. While parsing JSON I need

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.