gpt4 book ai didi

ios - UITableView didSelectRowAtIndexPath 选择多个单元格故障?

转载 作者:行者123 更新时间:2023-11-29 10:46:24 25 4
gpt4 key购买 nike

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

if ([selectedCell accessoryType] == UITableViewCellAccessoryNone) {

[selectedCell setAccessoryType:UITableViewCellAccessoryCheckmark];

} else {

[selectedCell setAccessoryType:UITableViewCellAccessoryNone];
}

[tableView deselectRowAtIndexPath:indexPath animated:NO];

好吧,这很奇怪。

发生了什么:当超过大约 10 行时,所有内容都会出现故障,如果我选择第一行,则会选择第 8 行和第 10 行。如果我取消选择第 8 行和第 10 行,则什么也不会发生。如果我选择第 8 行和第 10 行,它们会被选中,但第 3 行和第 5 行会被选中。

这也发生在 AppCoda 的教程项目中:http://www.appcoda.com/how-to-handle-row-selection-in-uitableview/

这只是 XCode 吗?如果是,这是一个巨大的故障。

最佳答案

cellForRowAtIndexPath 的实现中,您需要检查行是否被选中,并相应地设置辅助 View 。否则,附属 View 就是单元格进入重用队列时的任何内容。

关于ios - UITableView didSelectRowAtIndexPath 选择多个单元格故障?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22212776/

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