【问题标题】:Remove a subview from a UITableViewCell's content view从 UITableViewCell 的内容视图中删除子视图
【发布时间】:2011-06-06 14:29:19
【问题描述】:

如何从 UITableViewCell 的内容视图中删除子视图?

例如,我在单元格的内容视图中添加了以下子视图。

UIButton *b = etc.
[cell.contentView addSubview:b];

现在我想删除它: ?

【问题讨论】:

    标签: uiview uitableview


    【解决方案1】:

    此代码删除单元格上的所有子视图:

     if ([cell.contentView subviews]){
        for (UIView *subview in [cell.contentView subviews]) {
            [subview removeFromSuperview];
        }
    }
    

    【讨论】:

      【解决方案2】:

      一行

      [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多