<tfoot id='whZG1'></tfoot>

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

      <legend id='whZG1'><style id='whZG1'><dir id='whZG1'><q id='whZG1'></q></dir></style></legend>

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

        自定义 UITableViewCell 中使用的 UIButton 没有响应

        时间:2023-07-08
      1. <legend id='SUM4O'><style id='SUM4O'><dir id='SUM4O'><q id='SUM4O'></q></dir></style></legend>
          <bdo id='SUM4O'></bdo><ul id='SUM4O'></ul>
            <tfoot id='SUM4O'></tfoot>

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

                <i id='SUM4O'><tr id='SUM4O'><dt id='SUM4O'><q id='SUM4O'><span id='SUM4O'><b id='SUM4O'><form id='SUM4O'><ins id='SUM4O'></ins><ul id='SUM4O'></ul><sub id='SUM4O'></sub></form><legend id='SUM4O'></legend><bdo id='SUM4O'><pre id='SUM4O'><center id='SUM4O'></center></pre></bdo></b><th id='SUM4O'></th></span></q></dt></tr></i><div id='SUM4O'><tfoot id='SUM4O'></tfoot><dl id='SUM4O'><fieldset id='SUM4O'></fieldset></dl></div>
                  <tbody id='SUM4O'></tbody>
                • 本文介绍了自定义 UITableViewCell 中使用的 UIButton 没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我知道这个问题已经在 SO 中被问过几次.尽管尝试了这些,但我仍然无法解决我的问题.

                  I know this issue is already been asked few times in SO. Despite trying those out, I am still unable to solve my problem.

                  我在 UIViewController 中使用 UITableView.我有一个自定义 UITableViewCell ,其中有几个按钮.但是,我无法让 Button 响应 Click 事件.

                  I am using a UITableView inside a UIViewController. I have a custom UITableViewCell which has couple of buttons in it. However, I am not able to make the Button respond to Click event.

                  开发环境为 iOS 9 和 Swift 2

                  The development environment is iOS 9 and Swift 2

                  使用的片段:

                  BranchNearMeTableViewCell.swift 包含

                  BranchNearMeTableViewCell.swift contains

                  @IBOutlet weak var btnDetails: UIButton!
                  

                  查看控制器类

                  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
                          let cell = tableView.dequeueReusableCellWithIdentifier("branchNearTableCell") as! BranchNearMeTableViewCell
                  
                   cell.btnDetails.tag = indexPath.row
                          cell.btnDetails.addTarget(self, action: "showDetails:", forControlEvents: .TouchUpInside)
                  
                  }
                  
                  func showDetails(sender: UIButton){
                  
                          print("Button Pressed:")
                      }
                  

                  附加信息:

                  TableView 和 TableCellView 在界面生成器中禁用了用户交互,因为不希望整个单元格都可以点击.

                  TableView and TableCellView has User interaction disabled in Interface builder since don't want the entire cell to be clickable.

                  TableViewCell 内的 UIButton 启用了用户交互.

                  UIButton inside TableViewCell has User Interaction enabled.

                  作为一个 iOS 菜鸟,我可能犯了一个我可能忽略的愚蠢错误.

                  Being an iOS noob, I may be making a silly mistake which I might have overlooked.

                  我检查的类似问题包括:

                  Similar questions that I checked include:

                  SO1

                  SO2

                  SO3

                  非常感谢有关此问题的任何帮助.

                  I Deeply appreciate any help regarding this question.

                  推荐答案

                  我也会在表格视图单元格上将 userInteractionEnabled 设置为 true.我会阻止使用 UITableView allowsSelectionfalse

                  I would have userInteractionEnabled set to true on the table view cell as well. I would prevent taps using the UITableView allowsSelection to false

                  还要记得去掉tableView:cellForRowAtIndexPath:中的target和action,因为cell被回收了,按钮可能已经有了target和action,可能会加一秒.

                  Also remember to remove the target and action in tableView:cellForRowAtIndexPath: since the cells are recycled, the button might already have the target and action, it might add a second.

                  这篇关于自定义 UITableViewCell 中使用的 UIButton 没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UIControl - 更改分配的选择器:addTarget &amp;移除目标 下一篇:哪个更好,setEnabled 或 setUserInteractionEnabled?

                  相关文章

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

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

                    1. <legend id='dT5Az'><style id='dT5Az'><dir id='dT5Az'><q id='dT5Az'></q></dir></style></legend>

                    2. <tfoot id='dT5Az'></tfoot>