ios - 为什么我的 UICollectionView 单元格在我的 swift ios 应用程序中不可点击?

标签 ios swift uicollectionview uicollectionviewcell uicollectionviewdelegate

我在我的 swift 类中使用 UICollectionView,它被放置在我的 UIViewController 上。我在我的代码中将 collectionView 连接到导出,我设置了 delegatedatasource,然后我在我的应用程序中看到了结果。除了当我点击每个单元格时什么都没有发生之外,一切正常。

我的代码如下:

class UsersList: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {


@IBOutlet weak var tview: UICollectionView!

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    tview.backgroundColor = UIColor.whiteColor() //this works
    tview.delegate = self
    tview.dataSource = self
}

func collectionView(tview: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    print("You selected cell #\(indexPath.item)!")
    //this does not appear in the console :(
}

我还能做些什么来在控制台中看到打印消息吗?

最佳答案

在swift中,参数名和函数名共同标识一个函数。 UICollectionViewDelegate 有功能

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)

但不是

func collectionView(tview: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)

关于ios - 为什么我的 UICollectionView 单元格在我的 swift ios 应用程序中不可点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36487443/

相关文章:

ios - 删除 Storyboard中添加的对象

ios - 库和项目中的类名相同

ios - 还原列表 SwiftUI 中的底部填充

ios - Swift 项目的单元测试类

swift - Xcode Swift Firebase 如何创建 FIRAuth 的第二个实例

ios - UICollectionViewCell 中的导出为零

ios - ionic 应用程序构建失败,错误为 'linker command failed with exit code 1 (use -v to see invocation)'

javascript - 如何使用 Swift webView 调用在正文中返回 HTML 字符串的 JavaScript 函数?

ios - 如何在一个 CollectionView 中加载多个 nib 文件?

ios - 在 ContainerView 内的 UICollectionView 中计算单元格宽度