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

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

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

      1. 自定义 UITableViewCell 按钮操作?

        时间:2023-07-08

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

            <tfoot id='Sgl1I'></tfoot>
              <tbody id='Sgl1I'></tbody>

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

                  <bdo id='Sgl1I'></bdo><ul id='Sgl1I'></ul>
                  本文介绍了自定义 UITableViewCell 按钮操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在寻找解决方案,但似乎找不到适合我的解决方案.我有一个自定义单元格,里面有一个按钮.我的问题是如何将 indexPath 传递给 action 方法?

                  I've been looking around to find a solution to this, but can't seem to find one that works for me. I have a custom cell with a button inside. My problem is how do I pass the indexPath to the action method?

                  我现在正在做

                   [cell.showRewards addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventTouchUpInside];
                  

                  在我的 cellForRowAtIndexPath 方法中,我的方法是:

                  In my cellForRowAtIndexPath method and my method is:

                  -(IBAction)myAction:(id)sender{
                  NSIndexPath *indexPath = [self.tableView indexPathForCell:(MyCustomCell *)[sender superview]];
                  NSLog(@"Selected row is: %d",indexPath.row);
                  }
                  

                  有什么建议吗?谢谢.

                  推荐答案

                  虽然我觉得为按钮设置 tag 是一种方法.您可能需要编写代码以确保每次重用单元格时,都会在按钮对象上更新相应的标签.

                  While I feel setting tag for the button is one way to go. You might need to write code to make sure each time the cell gets reused, the appropriate tag gets updated on the button object.

                  相反,我觉得这可行.试试这个 -

                  Instead I have a feeling this could work. Try this -

                  -(IBAction)myAction:(id)sender
                  {
                  CGPoint location            = [sender locationInView:self.tableView];
                  NSIndexPath *indexPath      = [self.tableView indexPathForRowAtPoint:location];
                  UITableViewCell *swipeCell  = [self.tableView cellForRowAtIndexPath:indexPath];
                  
                  NSLog(@"Selected row: %d", indexPath.row);
                  //......
                  }
                  

                  实际上,您所做的是获取点击发生位置相对于您的 tableView 的坐标.获取坐标后,tableView 可以通过indexPathForRowAtPoint: 方法给你indexPath.你很好去追求这个......

                  Essentially what you are doing is getting the coordinates of where the click happened with respect to your tableView. After getting the coordinates, tableView can give you the indexPath by using the method indexPathForRowAtPoint:. You are good to go after this...

                  瞧,您不仅拥有 indexPath,还拥有点击发生的实际单元格.要从您的数据源中获取实际数据(假设它的 NSArray),您可以这样做 -

                  Voila, you have not just the indexPath but also the actual cell where the click happened. To get the actual data from your datasource (assuming its NSArray), you can do -

                  [datasource objectAtIndex:[indexPath row]];

                  这篇关于自定义 UITableViewCell 按钮操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:以编程方式设置 UIButton 标题 UILabel 字体大小 下一篇:iOS - 界面生成器:设置图像时 UIButton 标题消失

                  相关文章

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

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

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

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