【问题标题】:didSelectItemAtIndexPath is not calling in ios swiftdidSelectItemAtIndexPath 没有在 ios swift 中调用
【发布时间】:2015-12-01 07:04:27
【问题描述】:

当我只是选择/点击项目时,didSelectItemAtIndexPath 方法未被调用。但是当我长按项目然后didSelectItemAtIndexPath 它正在完美地调用工作。为什么会这样。我应该做错什么?

我添加了如下集合视图

collectionview_followers.frame = CGRectMake(0, 50, SCREEN_WIDTH, 150)

    collectionview_followers.delegate = self

    collectionview_followers.dataSource = self

    collectionview_followers.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "FollowersCell")

    collectionview_followers.backgroundColor = UIColor.clearColor()

    collectionview_followers.userInteractionEnabled = true

    collectionview_followers.allowsSelection = true

    view_collectionviewBG.addSubview(collectionview_followers)

单元格包含带有图像和标签的uiview

【问题讨论】:

  • 你在这个视图控制器上使用过任何手势吗?
  • 在这里显示一些代码!
  • 你应该添加一些我同意@SohilR.Memon 的代码。但是您可能没有将 allowsSelection 设置为 true(请参阅下面的答案)。
  • @rani 您正在使用“客户”视图上的任何按钮吗?
  • 确保你使用 didSelectItemAtIndexPath 方法而不是 didDeSelectItemAtIndexPath

标签: ios swift uicollectionview uicollectionviewcell


【解决方案1】:

确保在viewDidLoad 方法中将self.tableView.allowsSelection = true 设置在super.ViewDidLoad() 之前。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    相关资源
    最近更新 更多