Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete sections from static cell tableview

I'm trying to delete or hide a section inside a tableview with static cells on it. I am trying to hide it in function viewDidLoad. Here is the code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.tableView beginUpdates];
    [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:YES];
    [self.tableView endUpdates];

    [self.tableView reloadData];
}

Still the sections appear. I am using storyboards in it. Can you please help me out?Thanks!

like image 334
user1096503 Avatar asked Dec 15 '11 09:12

user1096503


1 Answers

I found it most convenient to hide sections by overriding numberOfRowsInSection.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ( section == 1 )
        // Hide this section
        return 0;
    else
        return [super tableView:self.tableView numberOfRowsInSection:section];
}
like image 64
masc3d Avatar answered Oct 27 '22 23:10

masc3d