简体   繁体   中英

UITableview: Fixed Section Headers

I am trying to create a single Tableview with multiple sections. Each Section would have a Section Header which would remain fixed (not float) and each section can have a number of rows.

What I am trying to achieve is to have:

Section 0 with 4 rows showing (and if 4 is exceeded allow the user to scroll without moving Section Header 1) Section 1 with 2 rows showing (and if this is exceeded allow the user to scroll)

My issues are:

  1. my UITablevViewStyle is Plain so the top header is fixed however the Header for section 1 keeps moving if I add more rows.

Any ideas welcome.

Just set your table view's UITableViewStyle to UITableViewStyleGrouped .

For doing so, go to your storyboard -> tableView -> style and select Grouped , or in case your doing it programmatically, at initialization use this function:

UITableView(frame: CGRectMake(0, 0, 100, 100), style: UITableViewStyle.Grouped)

You should add separate tableViews instead of sections in same tableView. That way your tableView's frame will be fixed and adding row to either won't push others frame down.

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