0

我以编程方式创建了我的 UICollectionView,设置委托、数据源。我可以滚动我的 UICollectionView,单击单元格内的按钮,但我无法选择我的单元格。DidSelect 函数根本不会触发!

我的代码:

let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.itemSize = CGSize(width: CGRectGetWidth(self.view.frame) - 15, height: 360)
    layout.scrollDirection = .Horizontal
    layout.minimumLineSpacing = -12

    // MARK: - Suggested Posts CollectionView
    self.suggestedPostsCollectionView = UICollectionView(frame: CGRect(x: 0, y: self.webView.scrollView.contentSize.height - 360, width: CGRectGetWidth(self.view.frame), height: 360), collectionViewLayout: layout)



    let nib = UINib(nibName: "SuggestedPostsCell", bundle: nil)
    suggestedPostsCollectionView.registerNib(nib, forCellWithReuseIdentifier: "suggestedPostsCell")

    suggestedPostsCollectionView.backgroundColor = UIColor.lightGrayColor()

    suggestedPostsCollectionView.delegate = self
    suggestedPostsCollectionView.dataSource = self
    suggestedPostsCollectionView.userInteractionEnabled = true
    self.webView.userInteractionEnabled = true
    self.scrollView.userInteractionEnabled = true

    self.scrollView.addSubview(suggestedPostsCollectionView)

我正在解决这个问题超过 2 周,但我不明白它为什么会发生。谁能帮我?

4

1 回答 1

0

试试prepareForSegue's 函数:

     let cellList = [YourObject]()

     let indexPath = self.collectionView?.indexPathForCell(YourCell() as UICollectionViewCell)
     let singleCell = cellList[indexPath!.row]

//example retrieving data from cell
singleCell.name = user_name
于 2016-08-27T15:10:47.473 回答