lucaconlaq
lucaconlaq

Reputation: 1541

only one section header

I'd like to have the section header (for an UITableView) for the uppermost cell only , a sort of header for the table that sticks to the top, showing some additional information about the uppermost cell.

is it somehow possible? if not (as I suppose since I've carefully read all the documentation) do you have any idea how to replicate this behaviour?

Upvotes: 0

Views: 625

Answers (3)

rob mayoff
rob mayoff

Reputation: 385890

You need to create your own view to use as the header. It will be simplest to make your custom header view be a sibling of the table view, and position it so that it's above the table view on the screen.

Since UITableView is a subclass of UIScrollView, your table view's delegate is also a scroll view delegate and receives the UIScrollViewDelegate messages. You want to implement this method:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

Each time your delegate receives that message, you want it to look at which table view row is at the top of the table view (using [tableView indexPathForRowAtPoint:tableView.contentOffset]) and update the contents of your custom header view accordingly.

Upvotes: 1

Jody Hagins
Jody Hagins

Reputation: 28409

This is hard (not impossible) with UITableViewController because it forces the tableView to be the root view.

If you implement your own controller, inherit from UIViewController instead of UITableViewController.

You must adopt the data source and delegate protocols, and implement the methods appropriately, but then you have a normal view as your root view. You can then add a UITableView in any location and size you want, with anything you want around it.

The only real restriction is static table views you build in IB. However, in that case, you can implement view controller containment, and just parent your table view controller into another controller, and give it a specific view to take over.

The first option is dead simple, but the second is an advanced technique, and you need to understand view controller containment to do it right.

Upvotes: 0

Steve
Steve

Reputation: 1840

Read the Apple documentation for UITableView. The property you're looking for is tableHeaderView.

Upvotes: 0

Related Questions