1
私はUICollectionViewを使用して外部APIからの製品を表示しています。製品はコレクションビューに完全に表示されますが、何らかの理由でセルを選択できません。最初のセルを選択することはできますが、スクロールして最初のセルをすばやくタップするだけです。ストーリーボードを使用してセグを作成しています。コントローラでは、データを次のビューに渡しています。以下のコードは次のとおりです。UICollectionViewは最初のセルのみを選択できるようにします
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.tableData.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: ProductsViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("productViewCell", forIndexPath: indexPath) as! ProductsViewCell
let product = tableData[indexPath.row]
cell.configureWithProduct(product, categoryId: "")
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print("Cell \(indexPath.row) selected")
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "productDetails") {
let svc = segue.destinationViewController as! ProductViewController;
let indexPaths : NSArray = self.collectionView!.indexPathsForSelectedItems()!
let indexPath : NSIndexPath = indexPaths[0] as! NSIndexPath
let product = tableData[indexPath.row]
svc.productId = product["merged"][0]["id"].int
}
}
didSelectItemAtIndexPathが呼び出されていない、それはprint文を示しており、その文が表示されていません。コレクションビューの上にビューがないことを確認しました。コレクションビューはうまくスクロールしますが、セルを選択することはできません。 –
それを考え出した。コード内にジェスチャーのビューを追加し、それを説明しませんでした。ありがとう! –
あなたがそれを理解したことは素晴らしい –