gpt4 book ai didi

ios - 在 UITableView 中隐藏单元格(在 Xamarin 中)

转载 作者:行者123 更新时间:2023-12-01 20:02:04 25 4
gpt4 key购买 nike

我想根据它是否有特定用户的任何数据来隐藏一个单元格。我目前的方法会导致错误 the requested operation resulted in a stack overflow .

public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
...
cell.TextLabel.Text = items.Keys.ElementAt(indexPath.Row);
cell.DetailTextLabel.Text = items[items.Keys.ElementAt(indexPath.Row)];

if (string.IsNullOrEmpty(cell.DetailTextLabel.Text)){
cell.Hidden = true;
cell.Tag = 3;
}
return cell;
}

public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.CellAt(indexPath); //ERROR HERE
if (cell.Tag == 3)
{
return 0;
}
return base.GetHeightForRow(tableView, indexPath);
}

如何避免此错误并正确隐藏一行?

最佳答案

我的猜测是 GetCell()来电GetHeightForRow()调用 GetCell()调用 GetHeightForRow() ...这就是您的堆栈溢出的来源。

您不应该使用视觉表示(= 单元格)来确定一行是否应该可见。您的(数据)模型应该对此负责。换句话说:无论您的 items 是什么类型的对象字典包含(可能是 Person - 我不知道),它应该有一个属性 IsVisible或类似的东西。然后在 GetHeightForRow()您访问该项目并检查该属性并确定行高将是多少,并为不可见的行返回 0。

顺便说一句:我不知道您上面代码的上下文 (*),但通常您不应该调用 base.GetHeightForRow() .该方法本身是作为 ObjectiveC 协议(protocol)实现的委托(delegate)的一部分。这意味着,没有 base .

(*) 如果您源自 UITableViewSourceUITableViewDataSource调用base没有副作用但是如果你直接在 UITableViewController 中实现方法您可能会看到 You_Should_Not_Call_Base_Exception .

关于ios - 在 UITableView 中隐藏单元格(在 Xamarin 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39709601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com