use*_*930 6 ios uicollectionview uicollectionviewcell uicollectionviewdelegate swift
我UICollectionView在我的 swift 类中使用它,它放在我的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 :(
}
Run Code Online (Sandbox Code Playgroud)
我还能做些什么来在控制台中看到打印消息?
小智 4
在swift中,参数名和函数名一起标识一个函数。UICollectionViewDelegate有功能
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
但不是
func collectionView(tview: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
| 归档时间: |
|
| 查看次数: |
4230 次 |
| 最近记录: |