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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:26:39+00:00 2026-06-10T06:26:39+00:00

I want to display a table with custom header titles. The table view is

  • 0

I want to display a table with custom header titles.
The table view is attached to a controller class that implements the tableview delegate and data source protocols but is not a subclass of UIViewController because the table is a subview to be displayed above another tableview.

some snippets of my code:
The tableview is created programmatically:

    _myListView = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStyleGrouped];

[_myListView setDataSource:self.myListController];
[_myListView setDelegate:self.myListController];
[_myListView setBackgroundColor:darkBackgroundColor];

where myListController is a strong property in the class.

For the number of rows in sections:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    …
    return count;    
}

The number of sections:

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [someDelegate sectionCount];
}

For the custom Header View:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, SectionHeaderHeight)];
    UILabel* sectionHeaderTitle = [[UILabel alloc] initWithFrame:CGRectMake(20, 3, 300, 24)];

    [headerView setBackgroundColor:[UIColor clearColor]];

    sectionHeaderTitle.text = [self myTitleForHeaderInSection:section];
    sectionHeaderTitle.textColor = [UIColor whiteColor];
    sectionHeaderTitle.textAlignment = UITextAlignmentLeft;

   [headerView addSubview:sectionHeaderTitle];

    return headerView;
}

For the custom headerViewHeight (as required since iOS5):

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if ( [self tableView:tableView numberOfRowsInSection:section] > 0) {
        return SectionHeaderHeight;
    } else {
        return 0;
    }
}

Sadly, the tableview does not display any section headers just as if I would return nil.
However, I have checked with a breakpoint, that the code actually returns an UIView.

Everything else works fine.

What am I missing? PLease, don’t hesitate to make me feel ashamed of my self.

  • 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-10T06:26:41+00:00Added an answer on June 10, 2026 at 6:26 am

    I seem to have found a solution:

    I have created a lazy loading strong property for each header view I want to display. (luckily there are only three)

    Now the views are shown.

    It seems that the header views got deallocated without the strong references before the table was rendered.

    Could it be that there is a connection to the class implementing the table view delegate and data source protocols is not a UIViewController?

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

Sidebar

Related Questions

I have a long list of data that I want to display in table
I have a custom UITableViewCell subclass, and a table view controller which I want
i want to display all posts in Post table with say id=5 ...... controller
I have Grouped Table View in which I want to display Contact details. But
Hey guys, I have an application that I want to display some data from
I want to display a table like this Generated from three database tables depends
Using vb.net 2008 I want to display a table in the form, so i
I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in
I want to display a ListView in table format. The ListView should have rows
I want to display all records from table of current autorized user in my

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.