There are some section in the table that does not contain any data and would like to hide that section.
How to do this?
So, to remove a cell from a table view you first remove it from your data source, then you call deleteRows(at:) on your table view, providing it with an array of index paths that should be zapped. You can create index paths yourself, you just need a section and row number.
UITableView with sections allows us to separate the list into different categories, so the list looks more organized and readable. We can customize sections as per our need, but in this tutorial, we are covering the basic UITableview with sections. Here's is the video if you prefer video over text. Let Create An App.
Actually, you can "hide" a section. If you want to use a similar behaviour to the built-in contacts app, where sections are hidden but still listed in the index on the right you can do the following:
Implement the UITableViewDataSource
protocol:
Return all section names (even hidden ones) in - the sectionIndexTitlesForTableView
method.
For each empty section, return nil
from the titleForHeaderInSection
method.
For each empty section return 0
for the numberOfRowsInSection
method.
I find this works better than deleting sections, because the user has consistent index navigation.
You can't "hide" a section as such, but you can "delete" it from the table view using the deleteSections:withRowAnimation:
method. This will remove it from the view, with an optional animation, without affecting your backing data. (You should, however, update the data anyway so that the section doesn't reappear.)
More info: UITableView class reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With