Question

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

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top