Alexander Theißen
Alexander Theißen

Reputation: 3889

Grouped UITableView subviews

Often I see layouts on the iPhone like the one I attached.enter image description here

How is this done best? With Interface builder or programmatically? How do i add a subview to the UITableView without occluding the actual table cells (i.e how do i set a margin to have space for subviews)?

Using Xcode4.2.

Upvotes: 0

Views: 858

Answers (4)

vikingosegundo
vikingosegundo

Reputation: 52227

A tableView has a header and footer and every section has those too.

to set the tableview's hear and footer (in my screenshot green), do:

[self.tableView setTableHeaderView: headerView];
[self.tableView setTableFooterView: footerView];

for header and footer for sections (blue), youl'll have to implement

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

and

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

screenshot

The code of the shown program you'll find at github

Upvotes: 2

dmarges
dmarges

Reputation: 361

Your best best would be to use interface builder. You can use interface builder to connect all of the actions to your code visually.

You can also use interface builder to change the positioning of the subview.

I hope this helps!

Upvotes: 0

omz
omz

Reputation: 53551

This is usually done with the tableHeaderView and tableFooterView properties of the table view.

Upvotes: 1

smparkes
smparkes

Reputation: 14053

The non-cell areas are usually done as section header and footer views.

Upvotes: 0

Related Questions