在运行时从静态UITableView删除行 [英] Deleting rows from a static UITableView at runtime

查看:79
本文介绍了在运行时从静态UITableView删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在笔尖中静态定义了所有节和行,是否可以在运行时从UITableView中删除行?

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

在以下故事板场景中,我可以在运行时删除地址2"字段吗?在这种情况下,我没有为UITableView提供数据源.

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.

推荐答案

我不知道删除",但是您可以使用tableView:heightForRowAtIndexPath:隐藏行.

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;
}

这篇关于在运行时从静态UITableView删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆