2

I have used storyboard to design a grouped tableView with simple, static content. I want to change the look of the section headers, but storyboard does not seem to offer this functionality, and I cannot determine how to get programmatic access to the section headers without building the interface from code.

For reference, the following SO question fully resolves the problem in the case that the dataSource is dynamic.

How to change text color for Section Headers in a Grouped TableView in iPhone SDK?

Is a similar solution possible where the content is STATIC and I am NOT implementing the UITableViewDataSource protocol?

Community
  • 1
  • 1
bgfriend0
  • 1,152
  • 1
  • 14
  • 26

3 Answers3

3

Here's an alternative approach. It will change the font size of ALL table headers and footers, which is one potential drawback, but it is simpler than the approach above I think

[[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class],nil] setFont:[UIFont systemFontOfSize:24.0f]];
software evolved
  • 4,314
  • 35
  • 45
2

If I remember correctly, you can click on a UIView object and drag it to the top of your table view in storyboard, and it will serve as it's header:

Otherwise, many of the tableview's delegate (not datasource) methods are still available even for static table views. So the delegate method:

-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

Will still be called. In here you can create a customized view to return as the header. This UIView can be created programmatically or in a .xib or storyboard view controller (via UIViewController.view).

Edit 1:

The drag and drop is for the UITableView's header, not the section. However, the method above will return a custom view for each section's header.

Chris
  • 1,663
  • 1
  • 15
  • 19
  • Sorry about the delay in response. Briefly, your suggestion did work--thank you.I tried a variation of your approach before posting this problem. I stumbled on the implementing the dataSource – bgfriend0 Dec 09 '13 at 19:20
  • Sorry about the delay in response. Briefly, your suggestion did work--thank you. I tried a variation of your approach before posting this problem. I adopted the UITableViewDelegate protocol and implemented the viewForHeaderInSection method. Unfortunately, the UITableViewDelegate protocol includes other methods that I did NOT want to implement, so I stopped. It turns out the storyboard adopted the UITableViewDelegate protocol, so instead of explicitly adopting it in my class interface I simply defined viewForHeaderInSection in my controller and set self.tableView.dataSource = self. Solved. – bgfriend0 Dec 09 '13 at 19:29
  • Nice. I'm glad it worked out for you. Thank you for coming back to let us know how it went. – Chris Dec 09 '13 at 21:36
0

You can not do this via Storyboard and static cell, only table header, table footer, cells can use your custom views.

avdyushin
  • 1,906
  • 17
  • 21