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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:41:42+00:00 2026-05-25T16:41:42+00:00

I want a subclass of UITableView that paints custom Section headers. I tryed as

  • 0

I want a subclass of UITableView that paints custom Section headers. I tryed as follows:

#import <UIKit/UIKit.h>
@interface MyTableView : UITableView
@end
@implementation MyTableView
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
  //my drawing code goes here
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
  //returns the height
}
@end

However when I use this class it draws the normal headers. What am I doing wrong?

When I Set those functions directly into a controller (without subclassing) it works fine.

UPDATE:
I already have many classes that use UITableView, I want to subclass it because it may be faster to just change the class that writing the needed classes. How can I change the titles by just changing the class, is it possible?

  • 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-25T16:41:42+00:00Added an answer on May 25, 2026 at 4:41 pm

    This is happening because you inherited the UITableView class and this methods are not from UITableView, they are from the UITableViewDelegate.

    It works on your controller because either you have set the delegate property of your UITableView pointing to your controller, or you are using a UITableViewController, which has the tableview delegate set automatically. (Actually, in your case, using a UITableViewController is worse because it already implements UITableView instead of your custom class).

    EDIT: Unfortunately, due to the delegation pattern used in UITableView class to change its section header views, it is not straightforward to implement this kind of action

    One way of doing that is providing these “helper” methods in your class, and then implement the delegate on each of your controllers to call these methods properly when the delegate method is fired.

    If this approach is acceptable you should even consider using a category with these methods instead of subclassing you UITableView, which would make the code much cleaner.

    Obviously you could set the UITableView delegate to be your custom class and then create another delegate for the calls you still want to be fired to the controller, such as cellForRowAtIndexPath, and then call this new delegate methods as soon as the tableview fires the methods, but this is by far the worst possible solution

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

Sidebar

Related Questions

I want to create a subclass of UITableView or UIScrollView that will have some
I want to subclass the built-in DropDownList in ASP.NET so that I can add
I want my UIView subclass to behave so that when it is fitted in
I want a non-editable TextField (or a subclass) that doesn't even have the caret
I want to have a UIView subclass that has a border image, but I
I have a custom NSActionCell subclass, and I want to use setTarget: message to
I made a UITableViewCell subclass, and now I want that subclass to be clever.
In an iPad application I'm developing, I want to show a UITableView that does
I want to subclass a UITableView as I want to create a reusable table
I want to create an NSOutlineView subclass where some of the entries look like

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.