相关疑难解决方法(0)

在UICollectionView中实现按钮单击

有没有办法从一个按钮内部获取按钮点击事件UICollectionViewCell?我用一个笔尖来填充集合视图,单元格有按钮但是它的动作没有被调用.我认为问题在于调用委托.我怎样才能解决这个问题?

我是如何创造的:

  1. 添加了一个空的笔尖,创建了一个集合视图单元格
  2. 添加了.h和.m文件,并将单元格nib的文件所有者作为创建的类
  3. 在课堂上写了一个动作.
  4. 将按钮连接到动作

有没有办法让我采取行动?我究竟做错了什么?

delegates ipad ios uicollectionview uicollectionviewcell

5
推荐指数
2
解决办法
2万
查看次数

在 UICollectionView Swift 中获取单击的 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; …

ios uicollectionview swift

0
推荐指数
1
解决办法
2247
查看次数