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!
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.)
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.
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 ...
- (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 } }
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