2

我有一个静态的UITableView,想隐藏一个表格单元格(正是我想隐藏单元格中的日期选择器)。我想在heightForRowAtIndexPath方法中做到这一点:

public override float GetHeightForRow (UITableView tableView, NSIndexPath indexPath)
{
    float height = this.TableView.RowHeight;

    if (indexPath.Row == 5 || indexPath.Row == 7) {
        height = 0.0f;
    }

    return height;
}

当我这样做时,单元格的内容与其他内容重叠。在我的例子中,日期选择器占据了整个屏幕。标签等也是如此。此外,分隔线似乎仍然存在。

如何暂时删除或隐藏包含内容的单元格?

您不必提供C#解决方案。我会自己翻译。顺便说一句:我使用的是 iOS 7.1

4

3 回答 3

3

选中“剪辑子视图”到您在 IB 中的单元格。不适用于单元格的“内容视图”。

要通过代码归档:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
    if(indexPath.row == 5 || indexPath.row == 7) {
        cell.clipsToBounds = YES;
    }
    return cell;
}
于 2014-09-18T09:16:43.220 回答
0

我会尝试减少numberOfRowsInSection:并考虑这一点cellForRowAtIndexPath:,但我不能 100% 确定这是否有效。

于 2014-09-18T08:48:05.603 回答
0

我建议您更新方法-

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (indexPath.Row == 5 || indexPath.Row == 7) {
        return 0.0f;
     }
    return 50; // some static value
}

我希望这能解决你的问题。

于 2014-09-18T08:51:32.387 回答