我在我的 swift 类中使用 UICollectionView
,它被放置在我的 UIViewController
上。我在我的代码中将 collectionView 连接到导出,我设置了 delegate
和 datasource
,然后我在我的应用程序中看到了结果。除了当我点击每个单元格时什么都没有发生之外,一切正常。
我的代码如下:
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/