Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 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?

question from:https://stackoverflow.com/questions/23969587/is-it-possible-to-have-a-fixed-uitableview-header-while-using-sections

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

1 Reply

0 votes
by (71.8m points)

There’s no way to maintain the header of a tableView fixed, but an useful approach when you need a unique header, is to use a UIViewController rather than a UITableViewController, and set the header (UIView) out from the tableView.

Something like this:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...