【发布时间】:2016-04-05 09:53:18
【问题描述】:
我正在使用 UICollectionView 显示来自外部 API 的产品。产品完美地显示在集合视图中,但由于某种原因,我无法选择任何单元格。我可以选择第一个单元格,但只有当我向上滚动然后快速点击第一个单元格时。我正在使用情节提要创建一个转场,并在控制器中将数据传递给下一个视图。代码如下:
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
}
}
【问题讨论】:
标签: ios swift uicollectionview