Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

ios - Is it possible to have a fixed uitableview Header while using sections?

This question should not be mixed up with this here.. These are two different things.

There is a good example how to use a UITableView Header on SO.

This all works fine and the main header is fixed on top as long as the style is set to plain.

But if I use sections, the main header no longer sticks to top and moves away while scrolling to the bottom.

In this method, I am returning the header for each section.

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

In this method I am setting the height for the header section above:

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

In this method, I am setting the real table header.

- (void)viewWillAppear:(BOOL)animated {
    ...
    self.recordTableView.tableHeaderView = headerView;
}

Is it even possible having a fixed table header, while using sections? What is an alternative solution to this please?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you want a UITableViewController (static cells/keyboard handling) and have a fixed header then you should use Containment. You can do this from a Storyboard by setting up a UIViewController with your fixed header and then using a Container View to embed the UITableViewController.

Storyboard object for Container View

Once you have your containing view setup, you right-click drag from the Container View to the View Controller you want to embed - the UITableViewController in this case.

enter image description here

You can access and get a reference to the contained View Controller (the UITableViewController) from the Container View Controller by implementing the prepareForSegue:sender: method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...