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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:43:15+00:00 2026-05-26T09:43:15+00:00

In my cellForRowAtIndexPath, I’m doing some custom formatting on a subview for when that

  • 0

In my cellForRowAtIndexPath, I’m doing some custom formatting on a subview for when that cell is selected. The complete function is:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIView *left;
    UIImageView *leftImage;
    UILabel *label;
    ArticleButton *btn;

    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (!cell)
    {
        cell = [[[UITableViewCell alloc]
                 initWithStyle:UITableViewCellStyleSubtitle 
                 reuseIdentifier:@"UITableViewCell"] autorelease];

        left = [[[UIView alloc] initWithFrame:CGRectMake(0, 2, 155, 139)] autorelease];
        leftImage = [[[UIImageView alloc] initWithFrame:CGRectMake(7,9,141,77)] autorelease];
        label = [[[UILabel alloc] initWithFrame:CGRectMake(6,87,141,48)] autorelease];
        btn = [[[ArticleButton alloc] initWithFrame:CGRectMake(0,2,155,139)] autorelease];

        left.tag = 0;
        leftImage.tag = 1;
        label.tag = 2;
        btn.tag = 3;

        [btn addTarget:self action:@selector(selectArticle:) forControlEvents:UIControlEventTouchUpInside];

        [cell.contentView addSubview:left];
        [cell.contentView addSubview:leftImage];    
        [cell.contentView addSubview:label];
        [cell.contentView addSubview:btn];
    }
    else
    {
        left = (UIView*)[cell viewWithTag:0];
        leftImage = (UIImageView*)[cell viewWithTag:1];
        label = (UILabel*)[cell viewWithTag:2];
        btn = (ArticleButton*)[cell viewWithTag:3];
    }

...load *entry


    NSURL *url = [NSURL URLWithString:[entry imageUrl]];

    FeedEntry* selectedEntry = [detailViewController detailItem];
    NSString* selectedTitle = selectedEntry.title;



    if ([selectedTitle isEqualToString:entry.title])
    {       
        [left setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cellbackground_sel.png"]]];  <-- PROBLEM IS THIS IMAGE NEVER CHANGES
        NSLog(@"selected row %@", selectedTitle);
    }
    else{
        [left setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cellbackground2.png"]]];
    }           

    [left setNeedsDisplay];

    [leftImage setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder.gif"]];
    [leftImage setContentMode:UIViewContentModeScaleAspectFill];
    leftImage.clipsToBounds = YES;

       [label setBackgroundColor:[UIColor clearColor]];
    label.textColor = [UIColor whiteColor];
    label.text  = [entry.title stringByAppendingString:@"\n\n"];
    label.numberOfLines  = 3;
    label.lineBreakMode = UILineBreakModeClip;
    label.font = [UIFont fontWithName:@"Arial-BoldMT" size:12];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;


    return cell;
}

The problem I’m having is with this section:

if ([selectedTitle isEqualToString:entry.title])
    {       
        [left setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cellbackground_sel.png"]]];
        NSLog(@"selected row %@", selectedTitle);
    }
    else{
        [left setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cellbackground2.png"]]];
    }           

Everything else works, but although I’m logging that it gets called, but the background of my subview to indicate that the row in question is a selected row, never changes. I’ve tried calling setNeedsDisplay, I’ve tried scrolling up and down trying to get the cells to dequeue and get recreated, it just never users the other image, even though it logs that the row being drawn was a selected row.

(Once I get this working, I need to implement the “right” section to have two “cells” in the one row and only one will be selected. That’s why I’m doing it this way with subviews in the cell).

What am I doing wrong?

  • 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-26T09:43:16+00:00Added an answer on May 26, 2026 at 9:43 am

    I think it is a problem to set the tag to zero. The documentation says:

    viewWithTag:

    Return Value
    The view in the receiver’s hierarchy whose tag property matches the value in the tag parameter.

    Discussion
    This method searches the current view and all of its subviews for the specified view.

    If think that most views tag is zero, even that of the current cell’s view. I think that you dont get the correct view out of it. Try not to use 0 as a tag to work with.

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

Sidebar

Related Questions

I was calling UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; from -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath in
I have the following Objective-c Function - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger
This - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (cell.accessoryType
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; in this method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; but I
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath I think if the table is empty, namely that
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @Cell; LocationsScreenTableViewCell *cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @Cell; UITableViewCell *cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //static NSString *CellIdentifier = @Cell; NSString *CellIdentifier
this is my cellForRowAtIndexPath . - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *TelephoneCellId = @TelephoneCellId; UITableViewCell *cell

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.