Tableview sub-section headers (row dividers)

In my app, I have a table view with sections (Example: Sports, Cars, Motorcycles). If the user taps one of these sections, it then shows a list of items under that header (Example: baseball, soccer). All I want to do is simply create some kind of divider between these row items that are already in a section. Again, for example:

  • Sports
    • Baseball
    • Soccer

I don't want the dividers to be able to be selected or have an action. I just simply want the rows to be divided so that they don't all run together. The individual rows themselves (baseball, soccer) will have actions upon being selected, however.


Note: Please explain your answers. I'm a beginner and want to learn, not mindlessly copy someone's work. Also please show how you set up your variables and structs. Some of the other tutorials didn't show this step and my confusion just simply compounds. I need a clear picture.

This is a bit off-topic for this forum, which is about the Swift language. SO and the Apple dev forum are probably better.

UITableView has no concept of subsections, only sections and rows. You could make your subsections just be regular rows, with a different appearance from the data rows and not respond to being tapped.

Terms of Service

Privacy Policy

Cookie Policy