Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide sections of a Static TableView

Tags:

I've found this tutorial which hides a section of a Static TableView: http://code-ninja.org/blog/2012/02/29/ios-quick-tip-programmatically-hiding-sections-of-a-uitableview-with-static-cells/

It works great but only without modifying it, if I add a section or a row, it works bad. I'm a beginner and I'm not able to modify it, can somebody help me hiding more than one section?

Thank you so much!

like image 828
Matte.Car Avatar asked Jul 20 '13 11:07

Matte.Car


People also ask

How do I hide a Tableview section?

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.)

What is Section in UITableView?

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.

What is Tableview in Swift?

Overview. Table views in iOS display rows of vertically scrolling content in a single column. Each row in the table contains one piece of your app's content. For example, the Contacts app displays the name of each contact in a separate row, and the main page of the Settings app displays the available groups of settings ...


1 Answers

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {                 if (section == 2 && _hideTableSection) {         //header height for selected section         return 0.1;      } else {         //keeps all other Headers unaltered          return [super tableView:tableView heightForHeaderInSection:section];      }   }  -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {             if (section == 2 && _hideTableSection) {         //header height for selected section         return 0.1;      } else {         // keeps all other footers unaltered         return [super tableView:tableView heightForFooterInSection:section];      }  }  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {     if (section == 1) { //Index number of interested section         if (hideTableSection) {             return 0; //number of row in section when you click on hide         } else {             return 2; //number of row in section when you click on show (if it's higher than rows in Storyboard, app will crash)         }     } else {         return [super tableView:tableView numberOfRowsInSection:section]; //keeps inalterate all other rows      }     } 
like image 183
Matte.Car Avatar answered Nov 02 '22 22:11

Matte.Car