Deleting rows from a static UITableView at runtime

跟風遠走 提交于 2020-01-24 13:11:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!