有没有办法从一个按钮内部获取按钮点击事件UICollectionViewCell
?我用一个笔尖来填充集合视图,单元格有按钮但是它的动作没有被调用.我认为问题在于调用委托.我怎样才能解决这个问题?
我是如何创造的:
有没有办法让我采取行动?我究竟做错了什么?
如何获取我在 Xcode 中使用 Swift for iOS 制作的 CollectionView 中单击的“Sheep”的索引?
class SheepsOverviewVC:
UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "class", for: indexPath) as! ClassesCollectionCell
if(sheeps.count > 0) {
cell.ClassImageView.image = UIImage(named: sheeps[indexPath.row] as! String)
cell.SheepName.text = names[indexPath.row] as? String
}
return cell
}
Run Code Online (Sandbox Code Playgroud)
我通过 Gui 在 TouchDown 上创建了一个发送事件:
@IBAction func clickingSheep(_ sender: UIButton) {
print("This will show info about the Sheep")
print(sender)
}
Run Code Online (Sandbox Code Playgroud)
但我得到的回应来自第二次印刷:
<UIButton: 0x7f9a63021d20; frame = (50 50; …