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

标签 ios objective-c uitableview

- (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/

相关文章:

iphone - 如何创建粗体但不粗体的 UIFont?

iphone - 将数据 UITableViewCell 传递到 UITableViewCell

ios - 为什么仅在 Real iphone 上从字符串创建日期失败?

ios - 从 TableView objective-c 中删除元素

swift - 在 Swift 中从 UITableView 中删除一行?

ios - 滚动时如何在静态单元格表​​ View 中创建弹性图像

jquery - 启动后 Cordova 3.4 iOS 白屏

ios - 如何检查添加到 Xcode 项目的 podfile 版本?

ios - NSArray valueForKey : @"@max.self"?

objective-c - 请求完成时向另一个 View Controller 发送通知