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

The Archive Base Latest Questions

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

I’m facing UITableViewCell setup issue when user scrolls down and up the table. The

  • 0

I’m facing UITableViewCell setup issue when user scrolls down and up the table. The cell looses the changes (red/green background image set in -didSelectRowAtIndexPath) once the grouped-table scrolls to another cell and comes back to that cell.

I’m showing a question and 4 answer choices in two sections using the below code..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *kCustomCellID = [NSString stringWithFormat:@"CustomCellID%d", ((100 * indexPath.section) + indexPath.row)];

    UITableViewCell *cell = nil;//[tableView dequeueReusableCellWithIdentifier:kCustomCellID];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCustomCellID] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    if (indexPath.section == 0) {
        cell.textLabel.text = questionText;
        cell.textLabel.textAlignment = UITextAlignmentCenter;
        cell.textLabel.font = FONT_QUESTIONTEXT;
        cell.textLabel.numberOfLines = 0;
    }
    else {
        cell.textLabel.text = [self.answerChoices objectAtIndex:indexPath.row];
        cell.textLabel.font = FONT_ANSWERTEXT;
        cell.textLabel.numberOfLines = 0;

        ConfigurationBase *configBase = [[ConfigurationBase alloc] initWithConfigurationType:kConfigTypeQuiz];

        NSString *backgroundImageName = [configBase.configInfo valueForKey:CKEY_IMG_ANSWER_BACKGROUND];
        NSString *leftImage = [configBase.configInfo valueForKey:[choicesLeftImages objectAtIndex:indexPath.row]];
        [configBase release];

        cell.backgroundColor = [UIColor clearColor];
        UIImageView *bgView = [[UIImageView alloc] initWithFrame:cell.frame];
        bgView.image = [UIImage imageNamed:backgroundImageName];
        cell.backgroundView = bgView;
        [bgView release];

        cell.imageView.image = [UIImage imageNamed:leftImage];
    }

    return cell;
}

And, when the user selects one of the choice, I change the background color right and wrong selection with green and red color. The code for changing the background for 2 rows is below..

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {   // Answer choice section.
        NSString *correctAnswerStr = [quizSession fetchCorrectAnswer];
        NSInteger correctAnswerIndex = -1;
        ConfigurationBase *configBase = [[ConfigurationBase alloc] initWithConfigurationType:kConfigTypeQuiz];

        NSString *correctAnsImageName = [configBase.configInfo valueForKey:CKEY_IMG_ANSWER_CORRECT_BACKGROUND];
        NSString *wrongAnsImageName = [configBase.configInfo valueForKey:CKEY_IMG_ANSWER_WRONG_BACKGROUND];
        [configBase release];

        UITableViewCell *answerCell = [tableView cellForRowAtIndexPath:indexPath];

        answerCell.backgroundColor = [UIColor clearColor];
        UIImageView *bgView = [[UIImageView alloc] initWithFrame:answerCell.frame];
        bgView.image = [UIImage imageNamed:wrongAnsImageName];
        answerCell.backgroundView = bgView;
        [bgView release];

        for (NSString *answerChoice in answerChoices) {
            ++correctAnswerIndex;

            if ([answerChoice isEqualToString:correctAnswerStr]) {
                // Correct Index obtained, so set the background color for it.
                NSIndexPath *correctIndexPath = [NSIndexPath indexPathForRow:correctAnswerIndex
                                                                   inSection:indexPath.section];
                UITableViewCell *correctAnswerCell = [tableView cellForRowAtIndexPath:correctIndexPath];

                correctAnswerCell.backgroundColor = [UIColor clearColor];
                UIImageView *bgView = [[UIImageView alloc] initWithFrame:correctAnswerCell.frame];
                bgView.image = [UIImage imageNamed:correctAnsImageName];
                correctAnswerCell.backgroundView = bgView;
                [bgView release];

                break;
            }
        }

        // Enable the 'next' button, allowing user to go for next question.
        self.navigationItem.rightBarButtonItem.enabled = YES;
        // Disable selection of answer until user go to next question.
    tableView.allowsSelection = NO;
}

Can anyone help me on this? TIA.

Regards.

  • 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-26T19:43:45+00:00Added an answer on May 26, 2026 at 7:43 pm

    Your method of retrieving the information about the background image name is very complicated and error prone. Please make sure everything works as expected by inserting NSLogs at the appropriate places or checking in the debugger.

    When dealing with the cell’s backgroundView property you will have to put this code into tableView:willDisplayCell:forRowAtIndexPath: rather than in cellForRowAtIndexPath. A simpler approach will save you time here again.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.