简体   繁体   中英

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?

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM