我以编程方式创建了我的UICollectionView,设置了delegate,dataSource。我能够滚动我的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)
我在两周内解决了这个问题,我不明白为什么会这样。任何人都可以帮助我吗?
答案 0 :(得分:0)
尝试prepareForSegue
的功能:
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