【问题标题】:UICollectionView didDeselectItemAt not get triggeredUICollectionView didDeselectItemAt 没有被触发
【发布时间】:2016-10-06 09:54:39
【问题描述】:

我有一个UICollectionView,在选择项目didDeselectItemAt not get triggered时,但选择其他项目时,第一个将被触发。为什么?

这是已经实现的方法:

override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {

    let userSetting = userSettings[(indexPath as NSIndexPath).row]
    selectedUserSettingRecordName = userSetting.id
    containerViewController!.performSegue(withIdentifier: "message", sender:self)

}

collectionView 上方没有可以干扰的视图。

【问题讨论】:

  • didSelect 与 didDeselect?
  • didSelectRowAtIndexPath returns wrong IndexPath 可能重复这个问题是在UITableView 而不是UICollectionView,但系统/原因是相同的。
  • 这是每个人最喜欢的错误之一:将didDeselectItemAtdidSelectItemAt 混在一起。

标签: ios swift uicollectionview swift3


【解决方案1】:

不是

didDeselectItemAt - 第二次调用,如果您选择之后的任何项目,它将调用

override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {

是的

didSelectItemAt - 第一次被调用,如果你选择它会调用的任何项目

 override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 2012-06-03
    • 2019-11-07
    • 2018-09-01
    • 2018-12-03
    • 2021-04-23
    • 2019-01-30
    相关资源
    最近更新 更多