问题
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
.
回答1:
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;
}
来源:https://stackoverflow.com/questions/19941813/deleting-rows-from-a-static-uitableview-at-runtime