UITableView选择节标题

时间:2018-07-30 12:06:58

标签: ios swift uitableview

我的TableView出现奇怪的行为

我在一个节标题中打开了isUserInteractionEnabled,因为我需要在其中插入collectionView。在做任何事情之前,我注意到当我点击该标题视图(它是UITableViewCell)时,它会触发didSelectRowAt方法,该方法具有该节中第一个单元格的索引(在标题的正下方)。有人知道导致该行为的原因以及如何将其关闭吗?

1 个答案:

答案 0 :(得分:0)

您的标题部分是您的UITableView的一部分。

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
}
  • 在此方法中,indexPath返回行和节indexPath.section ->返回UitableView的部分,您已经点击了,而indexPath.row->返回了该特定部分的位置,点击了。
  • 因此,无论您做什么,该函数都将被调用。您 需要重写表格视图的手势来避免这种情况。