[英]didDeselectRowAtIndexPath isn't called
我在UITableView
实现了didDeselectRowAtIndexPath
方法,其中包括多个选择。
出于某种原因, didDeselectRowAtIndexPath
不会调用didDeselectRowAtIndexPath
。 有什么建议么? (我没有意外拼错didSelectRowAtIndexPath
)。
谢谢!
有关细胞选择的一些注意事项:
didDeselectRowAtIndexPath
仅在单选UITableView
调用,如果用户单击与已选择的单元格不同的单元格。 didSelectRowAtIndexPath
来选择新行,调用didDeselectRowAtIndexPath
来取消选择前一行 UITableView
,未取消选择上一行,因此在didSelectRowAtIndexPath
处理取消选择 你可以使用你实现的委托方法获取单元格,并在检查它的选择后修改它,如下所示:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (cell.selected) {
// ... Uncheck
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
我目前使用带有多个选择的tableView,并且didDeselectRowAtIndexPath方法正在调用我(不同于上面答案中的第三个项目符号中所述)。
我注意到“预选”的单元格没有正确调用didDeselectRowAtIndexPath,除非我做了三件事:
示例代码:
if productsReceived!.rangeOfString(cell.productName.text!) != nil {
cell.accessoryType = .Checkmark
tableView.selectRowAtIndexPath(indexPath, animated: true, scrollPosition: UITableViewScrollPosition.None)
cell.selected = true
}
我希望这可以帮助那些尝试使用预选单元格实现多重选择的人。
如果我没弄错的话, UITableView
没有用于取消选择单元格的内置方法。 我相信你需要调用deselectRowAtIndexPath:
以便调用didDeselectRowAtIndexPath
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.