[英]didDeselectRowAtIndexPath isn't called
I've implemented the didDeselectRowAtIndexPath
method in a UITableView
which includes multiple selection. 我在
UITableView
实现了didDeselectRowAtIndexPath
方法,其中包括多个选择。
For some reason, didDeselectRowAtIndexPath
is not being called by the delegate. 出于某种原因,
didDeselectRowAtIndexPath
不会调用didDeselectRowAtIndexPath
。 Any suggestions? 有什么建议么? (I haven't accidentally misspelled
didSelectRowAtIndexPath
). (我没有意外拼错
didSelectRowAtIndexPath
)。
Thanks! 谢谢!
Some things to note about cell selection: 有关细胞选择的一些注意事项:
didDeselectRowAtIndexPath
is only called in a single-selection UITableView
if the user clicks a different cell than the one already selected. didDeselectRowAtIndexPath
仅在单选UITableView
调用,如果用户单击与已选择的单元格不同的单元格。 didSelectRowAtIndexPath
is called to select the new row, and didDeselectRowAtIndexPath
is called to deselect the previous row didSelectRowAtIndexPath
来选择新行,调用didDeselectRowAtIndexPath
来取消选择前一行 UITableView
with multiple-selection, the previous row is not being deselected, so your deselect is handled in didSelectRowAtIndexPath
UITableView
,未取消选择上一行,因此在didSelectRowAtIndexPath
处理取消选择 You can grab the cell using the delegate method you've implemented and modify it after checking it's selection like so: 你可以使用你实现的委托方法获取单元格,并在检查它的选择后修改它,如下所示:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (cell.selected) {
// ... Uncheck
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
I currently use a tableView with multiple selection, and didDeselectRowAtIndexPath method is calling for me (unlike what is stated in third bullet point in answer above). 我目前使用带有多个选择的tableView,并且didDeselectRowAtIndexPath方法正在调用我(不同于上面答案中的第三个项目符号中所述)。
I did note that cells that were "preselected", did not call didDeselectRowAtIndexPath correctly unless I did three things: 我注意到“预选”的单元格没有正确调用didDeselectRowAtIndexPath,除非我做了三件事:
Example code: 示例代码:
if productsReceived!.rangeOfString(cell.productName.text!) != nil {
cell.accessoryType = .Checkmark
tableView.selectRowAtIndexPath(indexPath, animated: true, scrollPosition: UITableViewScrollPosition.None)
cell.selected = true
}
I hope this helps someone who is trying to implement multiple selection, with preselected cells. 我希望这可以帮助那些尝试使用预选单元格实现多重选择的人。
If I'm not mistaken, UITableView
doesn't have a built in method for deselecting cells. 如果我没弄错的话,
UITableView
没有用于取消选择单元格的内置方法。 I believe you need to call deselectRowAtIndexPath:
in order for didDeselectRowAtIndexPath
to be called. 我相信你需要调用
deselectRowAtIndexPath:
以便调用didDeselectRowAtIndexPath
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.