简体   繁体   中英

How do I float all section header views (or keep all visible) on a UITableView?

I have a UITableView with two sections. I would like the header views for section 0 and section 1 to remain visible at all times regardless of scroll position. How can I accomplish this?

I can't think of an out-of-the-box (easy) solution. The default behavior only floats the section header(s) of currently visible rows.

I believe the approach would be to define viewForHeaderInSection as array (UICollectionView) of all the section header views before the current section (inclusive).

EDIT : (on second thought)

Can you detail the behavior you are looking? I haven't come across any app that does this. May be, you just need to change the approach to deal with the problem and achieve the same user behavior.

Eg - You can show only the section headers (with zero rows in all) and then when user tap one of the section then you insert the rows for that section. In fact, by default you can start with first section with filled in all its rows and when user taps on another section, you close (remove) the previous rows and insert rows in this section.

The easiest way. Or quickest way is to add a subview to the view as header 0 (separate to the tableview). Seeing as that is always top. So basically, slap the subview on top.

Then add Header 1 as normal found in

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

What you need to do is set the content inset of the scrollview(subclassed from uitableview) to the height of the subview that you added for header 0.

I had column headers that I wanted to remain visible at all times. I just created them as UIViews and added them as subviews to the view containing my UITableView.

This wasn't the solution I was originally headed for but I settled for it when no other option seemed straight forward.

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