'Set rounded corner when top or bottom cell is hidden in Inset Grouped table view

I have a UITableView with static cells. I am hiding some of the cells based on some conditions by setting the height of the cell as 0 in the heightForRowAtIndexPath method like below.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self shouldHideCell:indexPath]) {
        return 0;
    }
}

I am setting the style of the UITableView as Inset Grouped. So when I hide the first or last cell in a section the cells don't get the expected rounded corners properly. Is there any way to have the rounded corners when setting height as 0 for the first or last cell?

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source