ixany
ixany

Reputation: 6080

Hide a section / space between sections in UITableView

Under some circumstances I want to hide a section of an UITableView.

I’ve solved this by returning 0 rows for the section and nil for the section title.

After that the section is empty / not visible, but there’s a bigger gap than usual between the remaining sections.

enter image description here

I’ve tried to set the heightForHeader and heightForFooter to 0.0 but the space remains bigger.

How can I avoid this extra space between the sections?

Upvotes: 1

Views: 748

Answers (2)

ixany
ixany

Reputation: 6080

I’ve found a solution in this thread.

Long story short: You have to set self.tableView.sectionHeaderHeight = 0.0 as well as self.tableView.sectionFooterHeight = 0.0 i.e. in viewDidLoad.

For whatever reason the heightForHeader and heightForFooter delegate methods are ignored.

Upvotes: 1

Mina Gerges
Mina Gerges

Reputation: 327

Returning 0 rows for the section and nil for the section title does not mean that the section is hidden. It only means that the data of the section is cleared thats why the area equivalent to the section size still appears .

Solution :

You should put condition in numberOfSections & cellForRowAt functions that allow or disallow that section (for example with a Bool variable ) and when you want to hide it just turn the Bool false and reloadData of the UITableView.

Upvotes: 0

Related Questions