Ios 选中时,自定义CollectionViewCell具有默认值
我尝试在TableViewCell中使用collectionView。我使用代理,设置代理,等等-工作正常:Ios 选中时,自定义CollectionViewCell具有默认值,ios,swift,uitableview,uicollectionviewcell,Ios,Swift,Uitableview,Uicollectionviewcell,我尝试在TableViewCell中使用collectionView。我使用代理,设置代理,等等-工作正常: class DetailTableViewController: UITableViewController, UICollectionViewDataSource, UICollectionViewDelegate func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPat
class DetailTableViewController: UITableViewController, UICollectionViewDataSource, UICollectionViewDelegate
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell:VideoCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("videoCell", forIndexPath: indexPath) as! VideoCollectionViewCell
// Doing some stuff here
print(cell.videoNameLabel.text!) // Prints the right result
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print("\(indexPath.row) tapped")
let cell:VideoCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("videoCell", forIndexPath: indexPath) as! VideoCollectionViewCell
print(cell.videoNameLabel.text!) // Prints default value "Label"
}
这是我使用的单元格:
import UIKit
class VideoCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var videoNameLabel: UILabel!
@IBOutlet weak var imageView: UIImageView!
}
我有上面提到的功能-当我打开TableViewController时,它会为每个单元格显示正确的videoNameLabel文本。我在故事板中设置了标识符“videoCell”,并为该单元设置了类
但当我点击电池时,它会显示出来
0分接
标签
你有办法解决这个问题吗?我想使用单元格,但它有默认值
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! VideoCollectionViewCell
let text = cell.videoNameLabel.text!
print(text)
}