Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add header title for every Section in Table

I have four sections in my UITableView, how do I add a header for each section? I am using the following code, but it's not working.

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

    if (section == 0) 
        return @"Tasks";

    if (section == 1) 
        return @"Appointments";

    if (section == 2) 
        return @"Activities";

    if (section == 3) 
        return @"Inactivities";
}
like image 647
Rupesh Avatar asked Apr 11 '11 09:04

Rupesh


People also ask

Why is my header row not repeating in Word table?

Repeat column headings Right-click the table, and then click Table Properties. In the "Table Properties" dialog box, click the Row tab. In the "Options" group, make sure Repeat as header row at the top of each page is checked. Uncheck the box next to Allow row to break across pages.

How do I create a header row in a table in Word?

To designate a row as a header, select it, then right-click and select Table Properties. Select the Row tab, and check Repeat as header row at the top of each page.


1 Answers

Are you sure that you've implemented tableView:heightForHeaderInSection:?

In your case the titles were actually set but the headers' heights were 0 by default. Add this UITableViewDelegate method if you haven't yet:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { 
    return 40; //play around with this value
}

P.S.: Consider using switch statement in such methods

like image 160
knuku Avatar answered Oct 12 '22 12:10

knuku