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";
}
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With