【发布时间】:2017-11-28 09:06:26
【问题描述】:
我已经制作了一个自定义的 collectionview 单元格。我已经通过这段代码将它作为集合视图的标题:
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionElementKindSectionHeader {
let cell = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "HeaderCell", for: indexPath) as! GridHeaderCollectionViewCell
cell.pagePluginBtn.tag = 0
cell.tag = 0
cell.nameLabel.text = pageRecord["GroupName"] as? String
cell.pagePluginBtn.addTarget(self, action: #selector(TappedOnPagePluginBtn(sender:)), for: .touchUpInside)
return cell
}
abort()
}
func TappedOnPagePluginBtn(sender:UIButton){
print("in plugin")
}
单元格定义为:
class GridHeaderCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var pagePluginBtn: UIButton!
}
TappedOnPagePluginBtn() 根本没有被调用。有没有办法让collectionView的headerView中的按钮可以点击?
【问题讨论】:
标签: ios swift3 uibutton uicollectionview uicollectionviewcell