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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:37:26+00:00 2026-05-30T03:37:26+00:00

I have a simple tableViewCell build in interface builder. It contains a UIView which

  • 0

I have a simple tableViewCell build in interface builder.
It contains a UIView which contains an image.
Now, when I select the cell, the default blue selection background is shown, but the backgroundColor of my UIView is gone.

My UITableViewCell’s implementation file doesn’t do anything special. It just init’s & returns self and all I do in setSelected is call super.

How do I get my UIView backgroundColor to show when the tableView is selected?

  • 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-30T03:37:27+00:00Added an answer on May 30, 2026 at 3:37 am

    The problem here is that the [super] implementation of

    - (void) setSelected:(BOOL) selected animated:(BOOL) animated;
    

    sets all the background colors in the UITableViewCell to rgba(0,0,0,0). Why? Perhaps to make us all sweat?

    It is not that entire views disappear (as evidenced by the fact that if you change the views layer border properties, those are retained)

    Here is the sequence of function calls that results from touching a cell

    1. setHighlighted
    2. touchesEnded
    3. layoutSubviews
    4. willSelectRowAtIndexPath (delegate side)
    5. setSelected (!!! this is where all your view background colors are told to disappear)
    6. didSelectRowAtIndexPath (delegate side)
    7. setSelected (again) (Interestingly background colors not cleared on this call. What strangeness is going on inside that super method?)
    8. layoutSubviews (again)

    So your options are to

    1. Override – (void) setSelected:(BOOL) selected animated:(BOOL) animated; without calling [super setSelected:selected animated:animated]. This will give you the most technically correct implementation because a) the code is wrapped up inside the UITableViewCell subclass and b) because it is only called when needed (well twice when needed, but maybe there is a way around that). The down side is you’ll have to re-implement all the necessary functions (as opposed to unnecessary color clearing functions) of setSelected. Now don’t ask me how to properly override setSelected just yet. Your guess is as good as mine for now (be patient, I’ll edit this answer once I figure it out).
    2. Re-assert the background colors in didSelectRowAtIndexPath. This is not so great because it puts what should be instance code outside the instance. It has the upside that it is only called when it is needed, as opposed to …
    3. Re-assert the background colors in layoutSubviews. This is not great at all because layoutSubviews is called like A MILLION times! It is called every time the table refreshes, every time it scrolls, every time you grandmother gets a perm… like seriously, a million times. That means there is a lot of unnecessary background re-assertions and a lot of extra processing overhead. On the bright side it puts the code inside the UITableViewCell subclass, which is nice.

    Unfortunately re-asserting the background colors in setHighlighted does nothing because setHighlighted is called before all the background colors get set to [r:0 b:0 g:0 a:0] by the first call to setSelected.

    //TODO: Give a great description of how to override setSelected (stay tuned)

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

Sidebar

Related Questions

I have simple front controller plugin which contains this code: http://pastebin.com/m155c59b0 When session expire
I have simple regex \.*\ for me its says select everything between and ,
I have simple SSIS package which reads data from flat file and insert into
I have simple SSIS package in which On Error event handler I have created
I have simple multiple selection input <input multiple=true type=file name=image_name[] /> Now i would
I have simple user registration form. In which i am puting city as a
I have simple application with single AppDomain which is periodicaly launched on a server.
I have simple test project which creates a frame and adds one JTextPane to
i have a simple question. I have a UITableView in which you can add
Have simple C# console app which imports text data into SQL. It takes around

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.