ios - Swift UICollectionViewCell didSelectItemAt 不在单元格上打印标签名称

标签 ios swift uicollectionview

我已经通过 google 和 stack overflow 进行了查看,但找不到答案。我有一个 UICollectionView 并希望在单击单元格时将用户带到另一个 View 。但在这样做之前,我想单击模拟器上的单元格并将标签的名称打印在控制台中,这样我就可以从那里弄清楚如何编写 performSegue 方法。我在使用 didSelectItemAt 函数时遇到问题。

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let clothesCell = collectionView.dequeueReusableCell(withReuseIdentifier: "clothesCell", for: indexPath) as! closetCollectionViewCell
    clothesCell.clothingName.text = shirtStyle[indexPath.item]
    clothesCell.clothingColor.text = shirtColor[indexPath.item]
    clothesCell.clothingSize.text = "\(sizes[indexPath.item])"

    return clothesCell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    print(indexPath.item.clothingName)
}

最佳答案

在 didselectItem 中使用它打印所选项目

print(shirtStyle[indexPath.item])

关于ios - Swift UICollectionViewCell didSelectItemAt 不在单元格上打印标签名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47539104/

相关文章:

ios - SwiftUI 将按钮点击发送到 subview

ios - 问 : UITests - How to get collectionCell element inside collectionView nested with TableView cell?

swift - 无法在 Xcode Playgrounds 中初始化 UICollectionView

ios - 在 Swift 中使用 RestKit 和 CoreData

javascript - AngularJS Web App 缺少 CORS header 'Access-Control-Allow-Origin'

iphone - UIButton 上的 iOS 可拉伸(stretch)图像显示不稳定的角

swift - 如何在 Swift 中创建一个指针?

ios - UIView.animateWithDuration 不会在单独的 View Controller 上产生动画

ios - 保存 UICollectionViewCell 进度状态

ios - 核心数据是否会延迟刷新数据模型?