0

I need hide a UITableViewCell. I set backgroundColor to clear, but cell still visible. Please see the screenshot.

cell.backgroundColor = [UIColor clearColor];

enter image description here

Voloda2
  • 12,359
  • 18
  • 80
  • 130

1 Answers1

1

Normally, you wouldn't hide it this way. Rather, you should try not displaying it at all. In your table view controller's numberOfRowsInSection method, try something like this:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //... code regarding other sections goes here

    if (section == 1) { // "1" is the section I want to hide
        if (self.cellShouldBeVisible) {
            return 0; // show no cells
        } else {
            return 1; // show one cell
        }
    }
}

(you can replace self.cellShouldBeVisible with your own code of course)

If you want to go from displaying to not displaying the cell, set self.cellShouldBeVisible to the desired BOOL value and call [self.tableView reloadData];

winsmith
  • 20,791
  • 9
  • 39
  • 49
  • How do I add the buttons if I don't have a cell ? – Voloda2 Nov 14 '11 at 13:44
  • Ah, I see. You want the buttons to be displayed, but without the cell border, right? In this case, my answer won't help you. Instead: maybe you could add the buttons in a footer view? To do so, add the `- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section` method and make it return the view holding the buttons. – winsmith Nov 14 '11 at 14:19