Search code examples
objective-cxcode4

How can I add a title above the first row using Prototype cells?


I have a iPhone app using Prototype cells in a UITableViewController. I want to put a title right above the first row (where it says Prototype Cells). How do I do this? (Ignore what's in the first row...that's what I want the title to say)

enter image description here


Solution

  • Since you want to use dynamic prototypes cells, not static cells, it's best to do this in code. Override the method

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    
    

    in your table view controller and return the title you want for each section. If you only plan to have one section, then it's as easy as

    return NSLocalizedString(@"Title for Section", @"");
    

    But then if you only have one section, it may be bad UI design to label it, depending on what it is you're doing...