3

Is it possible to delete rows from a UITableView at runtime when all of the sections and rows are defined statically in a nib?

In the following storyboard scene, can I delete the "Addr 2" field at runtime? In this case I have not provided a data source to the UITableView.

enter image description here

Robert Karl
  • 7,598
  • 6
  • 38
  • 61

1 Answers1

2

I don't know about "delete" but you can hide the row using tableView:heightForRowAtIndexPath:.

- (void)methodToToggleAddr2CellVisibility
{
    self.addr2CellIsHidden = !self.addr2CellIsHidden;
    [self.tableView beginUpdates];
    [self.tableView endUpdates];
}

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (indexPath.section == 1 && indexPath.row == 1) { // the cell you want to hide
        if (self.addr2CellIsHidden == YES) {
            return 0;
        } else {
            return 44;
        }
    }
    return 44;
}
steharro
  • 1,079
  • 8
  • 18