• <bdo id='gptVU'></bdo><ul id='gptVU'></ul>

      1. <small id='gptVU'></small><noframes id='gptVU'>

        <legend id='gptVU'><style id='gptVU'><dir id='gptVU'><q id='gptVU'></q></dir></style></legend>
      2. <tfoot id='gptVU'></tfoot>
        <i id='gptVU'><tr id='gptVU'><dt id='gptVU'><q id='gptVU'><span id='gptVU'><b id='gptVU'><form id='gptVU'><ins id='gptVU'></ins><ul id='gptVU'></ul><sub id='gptVU'></sub></form><legend id='gptVU'></legend><bdo id='gptVU'><pre id='gptVU'><center id='gptVU'></center></pre></bdo></b><th id='gptVU'></th></span></q></dt></tr></i><div id='gptVU'><tfoot id='gptVU'></tfoot><dl id='gptVU'><fieldset id='gptVU'></fieldset></dl></div>
      3. iOS如何知道哪个按钮被按下了带有自定义委托的CollectionView

        时间:2023-09-12

          <small id='hdxMe'></small><noframes id='hdxMe'>

            • <bdo id='hdxMe'></bdo><ul id='hdxMe'></ul>
                <legend id='hdxMe'><style id='hdxMe'><dir id='hdxMe'><q id='hdxMe'></q></dir></style></legend>

                    <tbody id='hdxMe'></tbody>
                  <tfoot id='hdxMe'></tfoot>
                  <i id='hdxMe'><tr id='hdxMe'><dt id='hdxMe'><q id='hdxMe'><span id='hdxMe'><b id='hdxMe'><form id='hdxMe'><ins id='hdxMe'></ins><ul id='hdxMe'></ul><sub id='hdxMe'></sub></form><legend id='hdxMe'></legend><bdo id='hdxMe'><pre id='hdxMe'><center id='hdxMe'></center></pre></bdo></b><th id='hdxMe'></th></span></q></dt></tr></i><div id='hdxMe'><tfoot id='hdxMe'></tfoot><dl id='hdxMe'><fieldset id='hdxMe'></fieldset></dl></div>
                  本文介绍了iOS如何知道哪个按钮被按下了带有自定义委托的CollectionView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以我在一个集合视图中有一个单元格,里面有 3 个按钮.为了使用这些按钮触发代码,我实现了一个自定义委托.现在代码正在被触发,但我不知道代码是从哪个单元格触发的.我怎样才能最好地实现这一点?这是我的一些代码.协议:

                  So I have a cells in a collectionview with 3 buttons in it. To trigger code with these buttons I have implemented a custom delegate. Now the code is being triggered, but I don't know from which cell the code triggered. How can I best implement this? Here is some of my code. Protocol:

                  protocol OverViewDelegate {
                  func registerButtonClicked()
                  func evaluateButtonClicked()
                  func overviewButtonClicked()
                  }
                  

                  cellForItemAt:

                  cellForItemAt:

                  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sessionCell", for: indexPath) as? SessionCollectionViewCell
                      let session: SessionModel
                      session = DebugData.shared.sessionArray[indexPath.row]
                  
                      cell?.sessionImage.image = #imageLiteral(resourceName: "carControl")
                      cell?.sessionNameLabel.text = session.name
                      cell?.sessionLocationLabel.text = session.location
                      cell?.overViewDelegate = self
                  
                      return cell!
                  }
                  

                  单元格:

                  import UIKit
                  

                  导入 IBAnimatable

                  import IBAnimatable

                  @IBOutlet weak var sessionImage: UIImageView!
                  @IBOutlet weak var sessionNameLabel: UILabel!
                  @IBOutlet weak var sessionLocationLabel: UILabel!
                  @IBOutlet weak var sessionRegisterButton: AnimatableButton!
                  @IBOutlet weak var sessionOverviewButton: AnimatableButton!
                  @IBOutlet weak var sessionEvaluateButton: AnimatableButton!
                  
                  var overViewDelegate: OverViewDelegate?
                  
                  @IBAction func registerButtonClicked(_ sender: Any) {
                      overViewDelegate?.registerButtonClicked()
                  }
                  
                  @IBAction func overviewButtonClicked(_ sender: Any) {
                      overViewDelegate?.overviewButtonClicked()
                  }
                  
                  @IBAction func evaluateButtonClicked(_ sender: Any) {
                      overViewDelegate?.evaluateButtonClicked()
                  }
                  

                  如有任何帮助,将不胜感激.

                  Any help would be appriciated.

                  推荐答案

                  在Cell类中传递indexPath值在Button Click函数中返回indexPath

                  Pass indexPath value in Cell class return back indexPath on Button Click function

                  协议:-

                  protocol OverViewDelegate {
                  func registerButtonClicked(_ indexPath : IndexPath)
                  func evaluateButtonClicked(_ indexPath : IndexPath)
                  func overviewButtonClicked(_ indexPath : IndexPath)
                  }
                  

                  cellForItemAt:

                      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
                          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sessionCell", for: indexPath) as? SessionCollectionViewCell
                          let session: SessionModel
                          session = DebugData.shared.sessionArray[indexPath.row]
                  
                          cell?.sessionImage.image = #imageLiteral(resourceName: "carControl")
                          cell?.sessionNameLabel.text = session.name
                          cell?.sessionLocationLabel.text = session.location
                          cell?.overViewDelegate = self
                          cell?.indexPath = indexPath
                  
                          return cell!
                      }
                  

                  单元格:

                  @IBOutlet weak var sessionImage: UIImageView!
                  @IBOutlet weak var sessionNameLabel: UILabel!
                  @IBOutlet weak var sessionLocationLabel: UILabel!
                  @IBOutlet weak var sessionRegisterButton: AnimatableButton!
                  @IBOutlet weak var sessionOverviewButton: AnimatableButton!
                  @IBOutlet weak var sessionEvaluateButton: AnimatableButton!
                  
                  var overViewDelegate: OverViewDelegate?
                  var indexPath : IndexPath?
                  
                  @IBAction func registerButtonClicked(_ sender: Any) {
                      overViewDelegate?.registerButtonClicked(indexPath)
                  }
                  
                  @IBAction func overviewButtonClicked(_ sender: Any) {
                      overViewDelegate?.overviewButtonClicked(indexPath)
                  }
                  
                  @IBAction func evaluateButtonClicked(_ sender: Any) {
                      overViewDelegate?.evaluateButtonClicked(indexPath)
                  }
                  

                  使用 :-

                  let cell = tableView.cellForRow(at: indexPath)
                  

                  这篇关于iOS如何知道哪个按钮被按下了带有自定义委托的CollectionView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:何时在 NSURLConnection 委托上调用 release? 下一篇:在 Swift 中调用 Facebook 代表

                  相关文章

                  <small id='JDBEM'></small><noframes id='JDBEM'>

                  1. <tfoot id='JDBEM'></tfoot>
                    <legend id='JDBEM'><style id='JDBEM'><dir id='JDBEM'><q id='JDBEM'></q></dir></style></legend>
                      • <bdo id='JDBEM'></bdo><ul id='JDBEM'></ul>

                      <i id='JDBEM'><tr id='JDBEM'><dt id='JDBEM'><q id='JDBEM'><span id='JDBEM'><b id='JDBEM'><form id='JDBEM'><ins id='JDBEM'></ins><ul id='JDBEM'></ul><sub id='JDBEM'></sub></form><legend id='JDBEM'></legend><bdo id='JDBEM'><pre id='JDBEM'><center id='JDBEM'></center></pre></bdo></b><th id='JDBEM'></th></span></q></dt></tr></i><div id='JDBEM'><tfoot id='JDBEM'></tfoot><dl id='JDBEM'><fieldset id='JDBEM'></fieldset></dl></div>