<tfoot id='TK6XS'></tfoot>

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

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

          <bdo id='TK6XS'></bdo><ul id='TK6XS'></ul>

        iPhone - 如何确定在自定义 UITableViewCell 中按下按钮的单元格

        时间:2023-07-07

          <tfoot id='S88EK'></tfoot>

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

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

            <i id='S88EK'><tr id='S88EK'><dt id='S88EK'><q id='S88EK'><span id='S88EK'><b id='S88EK'><form id='S88EK'><ins id='S88EK'></ins><ul id='S88EK'></ul><sub id='S88EK'></sub></form><legend id='S88EK'></legend><bdo id='S88EK'><pre id='S88EK'><center id='S88EK'></center></pre></bdo></b><th id='S88EK'></th></span></q></dt></tr></i><div id='S88EK'><tfoot id='S88EK'></tfoot><dl id='S88EK'><fieldset id='S88EK'></fieldset></dl></div>
                <tbody id='S88EK'></tbody>
                  <bdo id='S88EK'></bdo><ul id='S88EK'></ul>
                  本文介绍了iPhone - 如何确定在自定义 UITableViewCell 中按下按钮的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前有一个 UITableView,其中填充了一个单独的 nib 中的自定义 UITableViewCell.在单元格中,有两个按钮连接到自定义单元格类中的操作.当我单击其中一个按钮时,我可以调用正确的方法,但我需要知道按钮被按下的是哪一行.每个按钮的标记属性为 0.我不需要知道整个单元格的时间被选中,只是在按下特定按钮时,所以我需要知道它是哪一行,这样我才能更新正确的对象.

                  I currently have a UITableView that is populated with a custom UITableViewCell that is in a separate nib. In the cell, there are two buttons that are wired to actions in the custom cell class. When I click one of the buttons, I can call the proper method, but I need to know which row the button was pressed in. The tag property for each button is coming as 0. I don't need to know when the entire cell is selected, just when a particular button is pressed, so I need to know which row it is so I can update the proper object.

                  推荐答案

                  更简单的解决方案是使用 (id)sender 定义按钮回调 并使用它来挖掘表格行索引.下面是一些示例代码:

                  Much easier solution is to define your button callback with (id)sender and use that to dig out the table row index. Here's some sample code:

                  - (IBAction)buttonWasPressed:(id)sender
                  {
                      NSIndexPath *indexPath =
                          [self.myTableView
                           indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
                      NSUInteger row = indexPath.row;
                  
                      // Do something with row index
                  }
                  

                  您很可能使用相同的行索引来创建/填充单元格,因此确定您的按钮现在应该做什么应该是微不足道的.无需玩标签并尽量保持它们井井有条!

                  Most likely you used that same row index to create/fill the cell, so it should be trivial to identify what your button should now do. No need to play with tags and try to keep them in order!

                  澄清:如果您当前使用-(IBAction)buttonWasPressed;只需将其重新定义为-(IBAction)buttonWasPressed:(id)sender; 额外的回调参数就在那里,不需要做任何额外的事情来获取它.还记得将您的按钮重新连接到 Interface Builder 中的新回调!

                  Clarification: if you currently use -(IBAction)buttonWasPressed; just redefine it as -(IBAction)buttonWasPressed:(id)sender; The additional callback argument is there, no need to do anything extra to get it. Also remember to reconnect your button to new callback in Interface Builder!

                  这篇关于iPhone - 如何确定在自定义 UITableViewCell 中按下按钮的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在swift 3中的tableview单元格内单击按钮标题 下一篇:以编程方式更改标题在 IB 中设置为属性的 UIButton 的标题

                  相关文章

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

                  • <bdo id='UdPkw'></bdo><ul id='UdPkw'></ul>
                  1. <tfoot id='UdPkw'></tfoot>

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

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