gpt4 book ai didi

objective-c - 不同部分中的 UITableViewCell 附件复选标记

转载 作者:行者123 更新时间:2023-11-29 04:48:19 26 4
gpt4 key购买 nike

我在 UITableView 中有 2 个部分。我想在我选择的行上启用 UITableViewCellAccessoryCheckmark。
2 个部分中只能有 1 个选中行。
我怎样才能做到这一点?我找到的示例仅展示了如何使用 1 个部分来完成此操作。

谢谢。

最佳答案

这适用于每个部分中任意数量的部分和单元格

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForItem:indexPath.row inSection:indexPath.section]].accessoryType = UITableViewCellAccessoryCheckmark;
[self deSelectOtherCellsInTableView:tableView Except:indexPath];
}

-(void)deSelectOtherCellsInTableView:(UITableView *)tableView Except:(NSIndexPath *)indexPath
{
for(UITableViewCell *cell in [tableView visibleCells]){
NSIndexPath *index = [tableView indexPathForCell:cell];
if(index.section == indexPath.section && index.row != indexPath.row){
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
}

关于objective-c - 不同部分中的 UITableViewCell 附件复选标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9289406/

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