gpt4 book ai didi

ios - 取消选择不可见行

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:37:15 25 4
gpt4 key购买 nike

我在更新 UITableView 中的行时遇到问题。在我的 tableView 部分中只能选择一行(可以有几个部分)。因此,当用户选择行时,我以编程方式取消选择此部分中的其他行。当取消选择的行可见时,一切正常。如果任何取消选择的行不可见,则它仍处于选中状态。但是为这一行调用了 didDeselectRowAtIndexPath。为什么?如何解决这个问题?

- (NSIndexPath*)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
// It is predefined group - only one row in section cab be selected
// Deselect other rows in section
for (NSIndexPath * selectedIndexPath in tagTableView.indexPathsForSelectedRows) {
if (selectedIndexPath.section == indexPath.section) {
[self tableView:tableView didDeselectRowAtIndexPath:selectedIndexPath];
[tableView deselectRowAtIndexPath:selectedIndexPath animated:YES];
}
}

return indexPath;
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tagTableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}

最佳答案

单元格的选定状态不应保存在 UITableViewCell 中,而应保存在填充单元格的对象(模型)中。

由于表格单元格被重复使用,因此状态代表填充它们的模型的最后状态。您应该将选定状态保留在填充单元格的对象中,或者保留一个选择索引路径数组。

-tableView:cellForRowAtIndexPath: 中设置该单元格的正确状态。如果您的模型对象保持选定状态,您可以根据该属性设置状态,或者如果您保留一个带有 select indexpaths 的数组,请检查该路径是否在数组中并相应地设置状态。

关于ios - 取消选择不可见行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21282603/

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