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

  • Home
  • SEARCH
  • 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 8096911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:35:28+00:00 2026-06-05T21:35:28+00:00

I have a TableView with 10 sections that are loaded from a plist file

  • 0

I have a TableView with 10 sections that are loaded from a plist file and I have switches with which some of the sections can be turned off. I need to set a specific background color for each section with the fact that the section can be disabled.

Example:

for section Black I need to set black background

for section Red I need to set red background

and so on…

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *tempHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,44)];
     tempHeaderView.backgroundColor=[UIColor blackColor];

     [tempHeaderView addSubView: tempHeaderLabel];
     return tempHeaderView;
}
  • 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-06-05T21:35:29+00:00Added an answer on June 5, 2026 at 9:35 pm

    Keep an NSArray of UIColor objects as an instance variable of your class (the view controller that acts as delegate/data source), say you call it sectionColors. You can initialize the colors in this array from values in your plist, or hard-code the colors.

    Then, use this code:

    -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        UIView *tempHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,44)];
    
    
        // This changed:
        tempHeaderView.backgroundColor = [sectionColors objectAtIndex:section];
    
        [tempHeaderView addSubView: tempHeaderLabel];
    
        return tempHeaderView;
        // Use 'return [tempHeaderView autorelease];' in a non-ARC environment
    }
    

    This is how you could initialize the array:

    // Assuming your table has three sections (indices 0 through 2)
    
    UIColor* colorForSection0 = [UIColor colorwithRed:redValue0 green:greenValue0 blue:blueValue0 alpha:1.0];
    // redValue0, etc. are floats between 0.0 and 1.0 that you can read from a .plist
    // Alternatively, store them as integers between 0 and 255, and divide them by 255.0 
    // and store on CGFloat variables before creating color.
    
    // ...Do the same for the other colors...
    
    // Now that you have the colors, create array and store in ivar 'sectionColors'
    sectionColors = [[NSArray alloc] initWithObjects: 
        ColorforSection0, ColorForSection1, colorForSection2, nil];
    

    (the code above should go inside the table view data source’s initializer)

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

Sidebar

Related Questions

I have a tableview, which has many sections. each section has just one cell.
When I have a table view with some sections which have their own headers
I have a tableview that is successfully incorporating an NSFetchedResultsController. However, I need the
I'd like to have a tableview header that can remain at the top of
I have a tableView with sections, which could be opened and closed. So, when
I have an app that includes a tableView . The tableView has several sections,
I have a tableview where the user can make sections of people using a
I have a tableview with four sections first section has 7 rows in that
i have TableView with Sections, the sections are Countries and i fetch them from
I have a TableView which has 2 sections and the 2nd section is only

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.