1. <tfoot id='jkIoO'></tfoot>
        <i id='jkIoO'><tr id='jkIoO'><dt id='jkIoO'><q id='jkIoO'><span id='jkIoO'><b id='jkIoO'><form id='jkIoO'><ins id='jkIoO'></ins><ul id='jkIoO'></ul><sub id='jkIoO'></sub></form><legend id='jkIoO'></legend><bdo id='jkIoO'><pre id='jkIoO'><center id='jkIoO'></center></pre></bdo></b><th id='jkIoO'></th></span></q></dt></tr></i><div id='jkIoO'><tfoot id='jkIoO'></tfoot><dl id='jkIoO'><fieldset id='jkIoO'></fieldset></dl></div>
      2. <small id='jkIoO'></small><noframes id='jkIoO'>

      3. <legend id='jkIoO'><style id='jkIoO'><dir id='jkIoO'><q id='jkIoO'></q></dir></style></legend>

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

        按下按钮时在 UITableViewCell 中查找按钮的 indexPath?

        时间:2023-07-08
            <bdo id='UqtL9'></bdo><ul id='UqtL9'></ul>

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

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

          • <legend id='UqtL9'><style id='UqtL9'><dir id='UqtL9'><q id='UqtL9'></q></dir></style></legend><tfoot id='UqtL9'></tfoot>
                <tbody id='UqtL9'></tbody>

                • 本文介绍了按下按钮时在 UITableViewCell 中查找按钮的 indexPath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  以下代码正确返回单元格:

                  The code below correctly returns the cell:

                  func findSuperView(sender:UIButton!) -> UITableViewCell { 
                      var superView : UIView? = sender.superview 
                      var foundSuperView : UITableViewCell! 
                  
                      while superView != nil && foundSuperView == nil { 
                          if let cell = superView as? UITableViewCell { 
                              foundSuperView = cell 
                              break 
                          } 
                          else { 
                              superView = superView?.superview 
                          } 
                      } 
                      return foundSuperView 
                  }
                  

                  但在 tableview 中查找 indexpath 时会崩溃:

                  But for finding indexpath in tableview it crashes:

                  var indexPath : NSIndexPath = self.table .indexPathForCell(findSuperView(sender))!
                  println("Section (indexPath)")
                  

                  我尝试了另一种方法,但没有成功:

                  And I tried another way, but it was not successful:

                  var button : UIButton = sender as UIButton; 
                  var touch: UITouch = events .allTouches()?.anyObject() as UITouch 
                  var location : CGPoint = touch.locationInView(self.table) 
                  var indexPath : NSIndexPath = self.table.indexPathForRowAtPoint(location)!
                  

                  推荐答案

                  我不知道是否有一个简单的方法来做到这一点.(其实有.看看@mustafa的第二个解决方案.)一种解决方法是在cellForRowAtIndexPath中将按钮的标签设置为indexPath.row, 然后你就可以访问按钮的标签来找出它属于哪一行.

                  I don't know if there is an easy a way to do this. ( Actually there is. Look at @mustafa's second solution.) A workaround is to set the button's tag to indexPath.row in cellForRowAtIndexPath, then you can just access the button's tag to find out which row it belongs to.

                  警告:此解决方法很脆弱.如果您允许从表中添加或删除行而不调用 tableView.reloadData(),它将无法正常工作.看看@mustafa 的解决方案,它更强大.

                  Warning: This workaround is fragile. It won't work correctly if you allow rows to be added or deleted from your table without then calling tableView.reloadData(). Look at @mustafa's solution which is much more robust.

                  这篇关于按下按钮时在 UITableViewCell 中查找按钮的 indexPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:iOS - 界面生成器:设置图像时 UIButton 标题消失 下一篇:UIButton 的选定状态在 iOS7 中不起作用

                  相关文章

                • <small id='6LGos'></small><noframes id='6LGos'>

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

                      <legend id='6LGos'><style id='6LGos'><dir id='6LGos'><q id='6LGos'></q></dir></style></legend>

                    1. <tfoot id='6LGos'></tfoot>

                        <bdo id='6LGos'></bdo><ul id='6LGos'></ul>